qt5base-lts/tests/auto/widgets
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
..
dialogs Merge remote-tracking branch 'origin/release' into stable 2013-11-26 10:51:34 +01:00
effects QtWidgets tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-28 02:02:14 +01:00
graphicsview Stabilize tst_QGraphicsItem 2013-12-03 11:42:13 +01:00
itemviews Stabilize tst_qabstractitemview 2013-12-11 09:55:39 +01:00
kernel Avoid crash due to accessing deleted QWidgetWindow object 2013-12-24 02:56:41 +01:00
styles Test password mask delay and characters on Mac. 2013-07-11 10:56:49 +02:00
util QCompleter::setFilterMode() add property filterMode. 2013-09-20 23:45:06 +02:00
widgets QSpinBox: allow positive values to be entered with the '+' prefix. 2013-12-05 23:57:53 +01:00
widgets.pro Moved tests into integrationtests/ and widgets/ 2011-10-20 19:45:41 +02:00