From b091ec9a22f841412552f6698bda85aa0ab42b6c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 14 Oct 2011 17:11:06 +0300 Subject: Avoid using 0 as the default winId in QPlatformWindow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the platform plugin does not reimplement QPlatformWindow::winId() to return a non-zero value, the default implementation provides a WId of 0. This breaks various scenarios with QWidgets which, for example in nativeParentWidget(), rely on internalWinId() being non-zero for TLWs. As a result, apps like collidingmice will crash with the 'minimal' platform plugin when they try to do markDirtyOnScreen for the graphics view's viewport widget because viewport()->nativeParentWidget() unexpectedly returns null, even though it should return the QGraphicsView. The patch makes the default value WId(1) in order to to avoid this. Change-Id: Iafef2e510e32b5610b8cef742313e9119ed64963 Reviewed-by: Samuel Rødal --- src/gui/kernel/qplatformwindow_qpa.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel/qplatformwindow_qpa.cpp') diff --git a/src/gui/kernel/qplatformwindow_qpa.cpp b/src/gui/kernel/qplatformwindow_qpa.cpp index b29112abef..fa1d3a33f8 100644 --- a/src/gui/kernel/qplatformwindow_qpa.cpp +++ b/src/gui/kernel/qplatformwindow_qpa.cpp @@ -166,7 +166,14 @@ Qt::WindowState QPlatformWindow::setWindowState(Qt::WindowState) /*! Reimplement in subclasses to return a handle to the native window */ -WId QPlatformWindow::winId() const { return WId(0); } +WId QPlatformWindow::winId() const +{ + // Return anything but 0. Returning 0 would cause havoc with QWidgets on + // very basic platform plugins that do not reimplement this function, + // because the top-level widget's internalWinId() would always be 0 which + // would mean top-levels are never treated as native. + return WId(1); +} /*! This function is called to enable native child window in QPA. It is common not to support this -- cgit v1.2.3