Results 1 to 2 of 2

Thread: Signals not working in a QThread

  1. #1
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Question Signals not working in a QThread

    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:

    Qt Code:
    1. void HTTPRequestHandler::sendNextRequest()
    2. {
    3. if(queue->size() <= 0) { return; }
    4.  
    5. request = queue->dequeue();
    6. reply = manager->get(*request->getRequest());
    7. qDebug() << "Request started : " << request->getRequest()->url().toString();
    8. connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestFailed()));
    9. connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
    10. }
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Signals not working in a QThread

    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.

Similar Threads

  1. Moving QObject to QThread causes signals to stop working
    By Ban-chan in forum Qt Programming
    Replies: 8
    Last Post: 13th July 2010, 21:39
  2. QThread SIGNALS
    By Max123 in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 13:17
  3. Working with QThread
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2009, 22:35
  4. QThread and signals
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2008, 02:44
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.