[Qt-interest] Qt signaling smarts...
Thiago Macieira
thiago at kde.org
Tue Nov 24 18:37:10 CET 2009
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 then
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.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091124/6b34e731/attachment.bin
More information about the Qt-interest-old
mailing list