PDA

View Full Version : Signals not working in a QThread



curreli
10th August 2010, 14:05
Hello,

I'm building a network module for an application, I need to be able to send requests from the main application thread and also from a RefreshThread.

I have a HTTPRequestHandler responsible for sending requests and receiving responses in which I connect two signals:



void HTTPRequestHandler::sendNextRequest()
{
if(queue->size() <= 0) { return; }

request = queue->dequeue();
reply = manager->get(*request->getRequest());
qDebug() << "Request started : " << request->getRequest()->url().toString();
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestFailed()));
connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
}


Everything works fine when the HTTPRequestHandler is executed in the main application thread but when it is executed in the RefreshThread, the request get sent but my requestFinished() slot never gets called.

I can't figure out why this should happen since my signals and slots are in the same class, namely HTTPRequestHandler and since I'm not sending signals between different threads.

Can someone help me figure out what's happening?

Thanks in advance!

curreli
10th August 2010, 16:04
I have figured out that, in fact, the request never finishes!

Indeed, reply->isFinished() returns false and reply->isRunning() returns true. That explains why my slot is never called.

However, I don't understand why the request would work if launched in the main thread but not in the RefreshThread.