How to ensure an object is deleted via deleteLater() before the event loop ended?



  • In a thread:

    someObject->deleteLater();
    exit();
    

    How to ensure someObject is deleted before the event loop ended?


  • Moderators

    @jronald
    doesn't make sende to use deleteLater() then.
    In such case you can use delete actually.

    You could force the events to be processed by the QApplication instance, but this raises the chance for side-effects and should by all means be avoided.



  • @raven-worx
    delete directly is ok, however delete in a event driven way also makes sense, I did it this way:

    connect(networkReply, &QNetworkReply::destroyed, this, &QThread::quit);
    

    By far delete directly is more efficient and not too complex, but the event driven ways is more general.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.