[Interest] Send signal from non-GUI thread

Bo Thorsen bo at fioniasoftware.dk
Fri Oct 5 08:20:50 CEST 2012

Hi Kio,

You can use QCoreApplication::postEvent to do this from your thread. You 
have to define a custom event for this, but that's not difficult.

It would have been simpler if the connect worked, but I'm afraid you 
need a bit more effort :)


Den 03-10-2012 12:43, Kio skrev:
> Hello,
> i'm trying to display a QMessageBox from a non-GUI thread. For this i use signal&slots:
> in a QMainWindow based object i defined the slot.
> In the sending object i defined the signal and in the c'tor i connect them.
> Then, from a background thread, i emit the signal.
> Connecting and emitting the signal is executed without error but the slot is never executed.
> Connect signal in c'tor:
>> connect(this,SIGNAL(showNewWarning(cstr)),parent,SLOT(showNewWarning(cstr)),Qt::QueuedConnection);
> Emit signal:
>>   emit showNewWarning("Programme did not fit in ram.");
> I really think this should work.
> This is Qt 4.8 on Mac OSX.
> I have no custom event loop in the QApplication object.
> The background thread was not created by my application. It is an audio callback:
> This may be the reason for the failure, but then i need a workaround. :-/
>   static OSStatus audioDeviceIOProc
> (
> 	AudioDeviceID			/*inDevice*/,
> 	const AudioTimeStamp*	/*inNow*/,
> 	const AudioBufferList*	inInputData,
> 	const AudioTimeStamp*	/*inInputTime*/,
> 	AudioBufferList*		outOutputData,
> 	const AudioTimeStamp*	inOutputTime,
> 	void* 					/*inClientData*/
> )
> { ... }
> Greetings from Germany,
> 	... Kio !

Bo Thorsen.
Fionia Software - Qt experts for hire.

More information about the Interest mailing list