----- Original Message ----
From: Thiago Macieira <[email protected]>
Em Terça-feira 24 Novembro 2009, às 16:54:04, BRM escreveu:
> > Assume the following:
> > - that the mainProgram class creates two threads - one based on QThread1
> > and the other based on QThread2. - that thread1Signal() is generated by an
> > internal instance class - that thread2Signal() interfaces to the slot of
> > an internal instance class - the 'this' pointer refers to the main
> > program.
> > - myQThread1 is an instance of QThread1.
> > - myQThread2 is an instance of QThread2.
> > - there may be multiple instances of QThread1 and QThread2, though
> > typically only one instance of QThread1 at a time.
> > Suppose the following connections are made by an instance of the
> > mainProgram: - connect(&myQThread1,SIGNAL(thread1Signal()),
> > this,SIGNAL(thread1SignalToThread2Signal()) - connect(this,
> > SIGNAL(thread1SignalToThread2Signal()), &myQThread2,
> > SIGNAL(thread2Signal())
> > QThread1::thread1Signal() -> mainProgram::thread1SignalToThread2Signal() ->
> > QThread2::thread2Signal()
> > Question:
> > - Is the Qt signal/slots mechanism smart enough to determine that the
> > thread1SignalToThread2Signal() does not need to exist and could be
> > eliminated (thus QThread1::thread1Signal() directly calls
> > QThread2::thread2Signal() ) ?
> No. A signal-to-signal connection works by emitting the target signal. Then
> the target signal's actions are performed the way they would have been if the
> signal had been emitted directly.
> If any of the connections are queued, this will cause queueing.
> > Or would the signal generation have to wait
> > until the event loop in the mainProgram's thread to call the second worker
> > thread?
> Yes, it would wait. If thread1Signal() is emitted inside thread 1's run()
> function, then the first connection above is a queued connection. That means
> the main thread's event loop will need to catch the queued connection and
> it would emit thread1SignalToThread2Signal() in the main thread.
> That will cause thread2Signal() to be emitted in the _main_ thread again,
> since that's the thread that myQThread2 is attached to.
> > Basically, do I need to try to figure out how to keep track of the instance
> > of QThread1 so that I can directly connect their signals, or will Qt do
> > some stuff for me already?
> I did not understand the question.
That last one I was just re-stating the previous questions in slightly
Thank you very much for answering my question. Looks like I will need to figure
to track the QThread1 object so I can make queued connections directly between
the two threads without having it go through the main thread.
Qt-interest mailing list