Lots of similar questions exists, but no suitable answer found.
I use a 3rd party library.
When some of the virtual methods on the lib's classes are called, these are called from a worker thread that has not been started by my application. This thread is not a QThread, nor could it ever be.
I can emit from this thread, but only if I connect the slot using Qt::DirectConnection. The upshot is that QObject::sender() in the SLOT will always return NULL. I wish to call deleteLater() for instance, but that can only be scheduled in a QThread.
I think I need to get back to the main thread, but how can I signal the object on the main thread?
Example: when the below method is called, it is done so on a thread created by 3rd party library.
/*virtual*/ bool MediaPlayer::onEof()
{
stopTransmit();
emit sigFinished(); // slots only called if bound using Qt::DirectConnection
deleteLater(); // dtor is never called
return false;
}
The connection is made from within a non-QThread context also, as follows:
/*virtual*/ void
SipCall::state_answer_call::onEntering(SipCall& ref)
{
...
MediaPlayer* player = new MediaPlayer;
ref.connect(player, SIGNAL(sigFinished()), SLOT(slotMediaFinished()), Qt::DirectConnection);
...
}
Without the explicit Qt::DirectConnection
, SipCall::slotMediaFinished()
is never invoked.