The slot caused by the signal will start in the thread for which it is associated QObject. In the current thread, a slot called directly will be launched. Here is a test program that demonstrates.
Conclusion:
main() thread: QThread(0x804d470)
run() thread: Thread(0xbff7ed94)
onRunning() direct call; thread: Thread(0xbff7ed94)
onRunning() signaled; thread: QThread(0x804d470)
Testing program:
#include <QtCore>
class Thread : public QThread
{
Q_OBJECT
public:
void run()
{
qDebug() << "run() thread:" << QThread::currentThread();
emit running();
}
public slots:
void onRunning()
{
qDebug() << "onRunning() thread:" << QThread::currentThread();
}
signals:
void running();
};
#include "threadTest.moc"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qDebug() << "main() thread:" << QThread::currentThread();
Thread t;
QObject::connect(&t, SIGNAL(running()), &t, SLOT(onRunning()));
t.start();
QTimer::singleShot(100, &app, SLOT(quit()));
return app.exec();
}
source
share