[Qt-interest] Qt signaling smarts...

Scott Aron Bloom Scott.Bloom at sabgroup.com
Tue Nov 24 17:14:22 CET 2009


You will be covered.. Before a QObject derived class is destroyed, it
emits a "destroyed()" signal, all objects connected to it, disconnect
from it at that point.

Note, if you are deleting in the middle of a event queue system blocking
algorithm, call deleteLater, which will keep the pointer alive till the
event system can delete it.

Scott

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of BRM
Sent: Tuesday, November 24, 2009 7:54 AM
To: qt-interest
Subject: [Qt-interest] Qt signaling smarts...

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

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list