From 275945f1449b3ff4e7421ab65a38b885cb338152 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Apr 2012 11:25:38 -0300 Subject: Add an assertion to deleteLater() before it modifies QEvent::d The deferred deletion functionality stores the event loop level nesting count in the QEvent d pointer. In Qt 4, this d pointer was not usable because we forgot to add a proper copy constructor and assignment operator to it, so the deleteLater() process stored the count here safely. Since Qt 5 now has non-implicit copy methods, the d pointer could be used in the future. If QEvent uses it, this assertion will trigger. Note that it doesn't apply to classes derived from QEvent, though. Change-Id: I8600c8e9379921e32aca166bc0a6c0b4c4ed799f Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qcoreapplication.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 7b26a01cbf..56674bc08e 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1074,6 +1074,12 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) { // remember the current running eventloop for DeferredDelete // events posted in the receiver's thread + + // check that QEvent's d pointer is unused before we store the loop level + // if further updates to QEvent have made the use of the d pointer necessary, + // then update this code to store the loop level somewhere else + Q_ASSERT_X(event->d == 0, "QCoreApplication::postEvent", + "Internal error: this code relies on QEvent::d being null"); event->d = reinterpret_cast(quintptr(data->loopLevel)); } -- cgit v1.2.3