[Qt-interest] Qt signaling smarts...
BRM
bm_witness at yahoo.com
Tue Nov 24 16:54:04 CET 2009
Suppose the following:
class QThread1 : public QThread
{
...
Q_SIGNALS:
void thread1Signal();
...
};
class QThread2: public QThread
{
...
Q_SIGNALS:
void thread2Signal();
...
};
class mainProgram...
{
...
Q_SIGNALS:
void thread1SignalToThread2Signal();
...
}
void main(int argc, char* argv[])
{
QApplication theApp(argc,argv);
mainProgram theProgram;
return theApp.exec();
}
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() ) ?
Or would the signal generation have to wait until the event loop in the mainProgram's thread to call the second worker thread?
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?
TIA,
Ben
More information about the Qt-interest-old
mailing list