Thread design advice needed
My question is inside the run function below ;)
Code:
{
Q_OBJECT
private:
QNetworkReply *m_reply;
public slots:
void gotNetworkHeader()
{
// do something
}
public:
TestObject
(QUrl url
) : m_url
(url
) {
}
void run()
{
QNetworkAccessManager nam;
m_reply = nam.head(QNetworkRequest(m_url));
connect(m_reply, SIGNAL(finished()), this, SLOT(gotNetworkHeader()));
//
// what do I do here to stop the thread from
// exiting until gotNetworkHeader has finished
// execution?
//
// I've tried exec(), but this seems to block QNetworkAccessManager
}
};
Re: Thread design advice needed
I just stumbled across this, which has some examples which are completely different to my design, but do exactly what I want.
http://doc.trolltech.com/qq/qq27-responsive-guis.html
Re: Thread design advice needed
simple
assign a private bool function
private:
bool stop;
in your constructor
stopped = false; //declare it
also use connect here itself in constructor
in run () function
Code:
while(stop)
{
//busy line ...
}
and in private slot
Code:
gotNetworkHeader()
{
stop = true;
}
Re: Thread design advice needed
Actually exec() would do the job. Just remember the QThread object lives in the main thread and not in the thread it controls.