qt5base-lts/tests/auto/widgets
Giuseppe D'Angelo 9ea1f0f8b9 Fix qobject_cast on partially destroyed QWidget/QWindow
QWidget and QWindow use bits in QObjectPrivate to provide for a couple
of shortcuts -- one in qobject_cast, and another in the isWidgetType() /
isWindowType() functions in QObject. These can be optimized by simply
looking at the bits, without actually doing more expensive runtime
casts.

These bits were set on construction, but not unset on destruction.  The
result was for instance that destroying a QWidget would report that the
object was still a QWidget when ~QObject was reached.

Fix this

1) by setting the bits only when QWidget / QWindow constructors start;

2) by resetting the bits once ~QWidget / ~QWindow are completed.
Technically speaking this is not 100% correct in the presence of data
members, but luckily those classes don't have any.

Amend an existing test for QWidget (whose comment said exactly the
opposite of what the test actually did) and add a test for QWindow.

Some other code was wrongly relying on isWidgetType() returning true
for destroyed QWidgets; amend it as needed.

[ChangeLog][QtCore][QObject] Using qobject_cast on partially constructed
or destroyed QWidget/QWindow instances now yields correct results.
Similarly, using the convenience isWidgetType() / isWindowType()
functions now correctly return false on such instances. Before,
qobject_cast (and the convenience functions) would erroneously report
that a given object was a QWidget (resp. QWindow) even during that
object's construction (before QObject's constructor had completed) or
destruction (after QWidget's (resp. QWindow's) destructors had been
completed). This was semantically wrong and inconsistent with other ways
of gathering runtime type information regarding such an object (e.g.
dynamic_cast, obj->metaObject()->className() and so on).

Pick-to: 6.3
Change-Id: Ic45a887951755a9d1a3b838590f1e9f2c4ae6e92
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-01-05 02:47:47 +01:00
..
dialogs QFileDialog: Fix adding default suffix when file path contains dot 2021-11-12 00:26:14 +03:00
effects Fix tst_qgraphicseffect on Wayland 2021-03-11 08:04:21 +01:00
graphicsview Stabilize tst_QGraphicsProxyWidget::scrollUpdate 2021-12-22 01:34:56 +01:00
itemviews QTableView: correctly toggle column selection when scrolled 2021-12-02 14:16:49 +00:00
kernel Fix qobject_cast on partially destroyed QWidget/QWindow 2022-01-05 02:47:47 +01:00
styles macOS: make the slider knob big enough for BigSur and Monterey 2021-11-15 09:30:25 +01:00
util Fix references to QGuiApplication::lastWindowClosed 2021-10-13 22:30:08 +02:00
widgets Widgets: setTransientParent() when a QMenu is a window 2021-12-08 13:45:36 +01:00
CMakeLists.txt Begin port of qtbase to CMake 2018-11-01 11:48:46 +00:00