qt5base-lts/tests/auto/widgets/kernel
Jian Liang 8fcab70408 Avoid crash due to accessing deleted QWidgetWindow object
Change childWidget->windowHandle() to childWidget->internalWinId() in
q_createNativeChildrenAndSetParent() to determine whether should we call
childWidget->winId().
This is because in some circumstances Qt will crash due to accessing
deleted QWidgetWindow object if we use windowHandle(). Think about the
following scenario:

1) create a widget A without parent and add two child widgets B and C to A

2) create a native widget D as the child of B, note that when we set
Qt::WA_NativeWindow attribute to it, its QWidgetWindow will be created
which means its windowHandle() is not null.

3) create a top level widget E as the child of C and show it. This will
make Qt call createWinId() to A and then
q_createNativeChildrenAndSetParent() will be called to create A's native
children recursively and finally make D's QWidgetWindow object become a
child of A's QWidgetWindow object. Please note here that B will not become
a native widget just because at that moment windowHandle() of D is not
null and Qt will not call winId() to its parent B

4) Set A's parent to another widget which has been shown, setParent_sys()
will be called to A and then Qt will call destroy() to A. in destroy() Qt
will try to call destroy() to its children recursively with a condition that
the child has Qt::WA_NativeWindow been set. But D's parent B is not a native
widget right now so B and D is not destroyed. Qt will then deleted the
QWidgetWindow object of A, since E's QWidgetWindow object is a child of
A's QWidgetWindow object, it will also be deleted. Now E hold a deleted
pointer of QWidgetWindow object. This is the source of crash later.

Task-number: QTBUG-35600

Change-Id: I97a20a68e626ee62b15bb4eae580e26f8948923b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
2013-12-24 02:56:41 +01:00
..
qaction QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qactiongroup QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qapplication Widgets: Never revoke focus by click on focused widget. 2013-11-18 20:38:41 +01:00
qboxlayout Add widget replace function to QLayout 2013-09-21 23:17:55 +02:00
qdesktopwidget QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qformlayout QFormLayout: Avoid assertion with negative spacings. 2013-11-15 09:15:13 +01:00
qgridlayout Add widget replace function to QLayout 2013-09-21 23:17:55 +02:00
qlayout QSizePolicy - add retainSizeWhenHidden 2013-07-10 09:26:31 +02:00
qshortcut QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qsizepolicy QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qstackedlayout Add widget replace function to QLayout 2013-09-21 23:17:55 +02:00
qtooltip QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qwidget Windows: Don't cover the taskbar when maximizing frameless windows 2013-12-06 13:52:34 +01:00
qwidget_window Avoid crash due to accessing deleted QWidgetWindow object 2013-12-24 02:56:41 +01:00
qwidgetaction QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qwidgetmetatype QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qwidgetsvariant QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
qwindowcontainer Fix crash when windowcontainer is used in a dockwidget 2013-11-20 14:10:37 +01:00
kernel.pro Introducing QWidget::createWindowContainer() 2013-01-25 14:11:07 +01:00