It depends on your programs. Here is an example:
void MyThread::run(){ Curl * curl = new Curl(); connect( curl, SIGNAL(OnTransfer(QString)), this, SLOTS(OnTransfer(QString)) ); connect( curl, SIGNAL(OnDone()), curl, SLOTS(deleteLater()) ); curl->Download("http://google.com"); exec(); // this is an event loop in this thread, it will wait until you command quit() } void MyThread::OnTransfer(QString data){ qDebug() << data; }
Without exec (), OnTransfer will never be called. BUT, if you create curl out run with this (suppose the parent of MyThread is the main thread) as the parent:
MyThread::MyThread(){ curl = new Curl(this); connect( curl, SIGNAL(OnTransfer(QString)), this, SLOTS(OnTransfer(QString)) ); start(); } void MyThread::run(){ curl->Download("http://google.com"); }
This one will work as you expected. OnTransfer will be called.
Rozi
source share