PDA

View Full Version : signal-slot connection requires thread must be QThread?



Bing
10th September 2008, 17:23
Based on Qt document, "Qt provides thread support in the form of platform-independent threading classes, a thread-safe way of posting events, and signal-slot connections across threads.", I am wondering to make Qt signal-slot connection across threads work, do i have to make sure all the threads are created with QThread or Qt GUI thread?

For example, i have a Qt GUI thread, and i have a library running in another thread (Win32 thread). and in my GUI program, i override some virtual functions provided by the library which act as the callback function (based on publish/subscribe pattern). so the codes in the overridden virtual functions are actually executed in the Win32 thread. can i emit signal in the overridden function and let the slot in Qt GUI thread to connect with it to make the Async calling work?

Thanks

jacek
11th September 2008, 20:45
can i emit signal in the overridden function and let the slot in Qt GUI thread to connect with it to make the Async calling work?
I'm not sure us the automatic connections will work properly, but queued one should work. A queued signal is delivered using QCoreApplication::postEvent() which is thread-safe.