|
|
Yes, the problem is that each QThread object will handle the events on
the thread they were created on. So, currently, all the subthreads, will
execute their slots and signals in mainthread. To get around this,
create internal objects inside the threads, that handle the work. The
threads then just become proxies to these inner threads. It's kinda
complicated I know, but, if you think about it, thread signals like
"finished" and "terminated", can't be fired off inside the thread, as
well the thread will have already disappeared by then. So the QThread
object needs to be based in the thread that created it.
Joachim Zettler wrote:
> Thank you for your answer Bill,
>
> yes in fact at the moment I just start my mainthread in the
> userinterface class by creating the instance of mainthread and then
> directly mainthread->start()
>
> Inside mainthread in the constructor I generate myself the instances
> of the other thread-classes (might this already be the problem??)
>
> So to summarize: Bevore I do the first start() all instances have been
> created through the creation of the mainthread instance.
>
> To start the other threads...I then click a button inside the ui-class
> and use the signal to start a function inside mainthread that is just
> starting all other threads. These connections are set up inside
> mainthread.
>
> Best regards,
>
> Joachim
>
> 2007/3/27, Bill KING <bill.king@xxxxxxxxxxxxx
> <mailto:bill.king@xxxxxxxxxxxxx>>:
>
> 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
>
>
--
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/
|
|