QObject::deleteLater across a QThread

前端 未结 3 1232
甜味超标
甜味超标 2020-12-11 04:03

I\'m looking for a solution to schedule the deletion of an object across threads. The docs about how deleteLater behave are not entirely clear. Can I call this

3条回答
  •  佛祖请我去吃肉
    2020-12-11 04:47

    Looking at the Qt 4 code and Qt 5 code, deleteLater() just invokes QCoreApplication::postEvent() which is explicitly declared thread-safe. So, it should be fine to just call it directly. As the event queue is processed in the object's owner thread, deletion will happen in thread A.

    Only Qt 5 QObject documentation explicitly lists deleteLater() as thread safe. If you want to completely rely on documented behaviour in Qt 4, use postEvent().

提交回复
热议问题