Signal emission for destructed receiver across threads
-
Hi,
I have signal/ slot connecting mechanism like this. Sender and receiver are in different threads.
QObject::connect(recall_cine_control_manager.get(), SIGNAL(signalRenderRecalledFrame(const usimage::Image2dBase::ptr&, const usimageprovider::StreamType&, const CineControlManager::PlaybackTimeTracker&, bool)), recall_viewer.get(),
SLOT(displayRecalledFrame(const usimage::Image2dBase::ptr&, const usimageprovider::StreamType&, const CineControlManager::PlaybackTimeTracker&, bool)), Qt::DirectConnection);Here the receiver gets destructed earlier, so when sender emits signal, the application crash.
I used Qt::DirectConnection, Does Qt::QueuedConnection solve this problem, how?How Queued connection knows about the status of the receiver before signal emission / or disconnection?
-
@inforathinam said in Signal emission for destructed receiver across threads:
I used Qt::DirectConnection
You must not use Qt::DirectConnection when you want to send signals from one thread to another. See https://doc.qt.io/qt-5/threads-qobject.html#signals-and-slots-across-threads
Normally you don't need to specify the connection type at all - Qt knows which one it has to use.