Joachim Zettler wrote:
> Dear all,
> I have a strange problem with an app that uses a lot of threads (5).
> (I use qt 4.2.1)
> The app should listen to the serial port until something happens there
> (I use WaitCommTimeout, WIN32 COM). Because the program execution is
> freezed as long as the waitcommtimeout listens to the port, i shifted
> this funktion to another thread.
> Now I have the following situation: A UserInterface thread that
> generates an instance of "mainthread". This thread itself is
> generating the different worker threads and is doing the
> synchronisation between them. Therefore in the mainthread i did a lot
> of signal->slot connections. One connection is for example the call to
> watch() if a signal is emitted in mainthread. Watch itself is running
> in a worker thread and is performing the listening to the serial port.
> After I connected everything and also started all the threads i try to
> test it and my app freezes everytime the signal dowatch() is emitted.
> If I send a "pseudo" signal to the serial port, then the
> waitcommtimeout gets his event and the app is running normally..but
> this is not a solution to my problem :( Only the worker thread should
> be freezed and nothing else :(
> Can anybody of you help me out on how i can solve this problem?
Okay, it sounds like your creating the listening objects in the thread
constructor (or even worse, creating the signals as part of the thread
object). What you need to do is create a dedicated object that has the
actual slots. Create these objects inside the run function of the
thread, and then these will have their event loops tied to the actual
thread. You can create proxy slots in the thread object, that can then
forward on the slot call onto the internal object. Basically, to
reiterate, a thread needs to have its event loop on the main/creating
thread, and any object created in the threads constructor will also have
its event loop on the main/creating thread. Any object created inside
the run event however will have it's event loop in the thread itself.
Hope this helps.
Bill King, Software Engineer
Trolltech, Brisbane Technology Park
26 Brandl St, Eight Mile Plains,
QLD, Australia, 4113
Tel + 61 7 3219 9906 (x137)
Fax + 61 7 3219 9938
mobile: 0423 532 733
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/