DeleteLater vs. delete, possibly nested event loops and OS X



  • Hello,

    I've gotten in a bit of a discussion when I submitted two KDE review reports for patch that seem to prevent a crash I was seeing in KDevelop, and that's based on http://qt-project.org/forums/viewthread/38406/#162801 .

    The latest of the reports is https://git.reviewboard.kde.org/r/120150

    My question is simple: should one use deleteLater to dispose of objects that correspond to a GUI element even when that element is not in use in other threads? Is that a (necessary) precaution on OS X only, or also on other OSes?


  • Lifetime Qt Champion

    Hi,

    It's generally good practice to let Qt's event loop handle the destruction of widgets. There might be some events still needing to be process (or in this case discarded) You might be deleting a parented widget which would be also destroyed because of it's parent being deleted right after you deleted that widget etc.

    Also, you can't use GUI elements in other threads. Only the main thread is available for that. However, you can update a widget through e.g. signals and slots.

    Hope it helps



  • As I thought, much like ObjC's retain/release scheme (which is like Qt's reference counting, except that it's also the main mechanism to handle object disposal).


Log in to reply
 

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