Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
6.5.0 RC
Description
Documentation here:
https://doc.qt.io/qt-6/qcoreapplication.html#processEvents
says:
"In the event that you are running a local loop which calls this function continuously, without an event loop, the DeferredDelete events will not be processed."
However, it does process them if deleteLater() was called during another call to processEvents().
For example, it will destroy O during the second call to processEvents:
class O : public QObject { ~O(){ qDebug("O has been destroyed"); } }; int main(int argc, char **argv) { QApplication app(argc, argv); QTimer::singleShot(0, [] { auto o = new O; QTimer::singleShot(0, [o]{ o->deleteLater(); qDebug("delete later called"); }); qApp->processEvents(); qDebug("first processEvents() done"); qApp->processEvents(); qDebug("second processEvents() done"); }); app.exec(); }
It does say "without an event loop", but that is not true either as removing the app.exec() still has the same behavior, although it needs one extra processEvents() call. For example:
auto o = new O; QTimer::singleShot(0, [o]{ o->deleteLater(); qDebug("delete later called"); }); qApp->processEvents(); qDebug("first processEvents() done"); qApp->processEvents(); qDebug("second processEvents() done"); qApp->processEvents(); qDebug("third processEvents() done");
I don't know if this is just out dated documentation or a bug, but this behavior can cause a crash. If this is just a documentation issue, maybe there should also be some way to tell processEvents to ignore deferred deletes.