Important: Please read the Qt Code of Conduct -

[Solved] QNetworkAccessManager/QThread/Signals & Slots

  • I'd like to see if I can explain this at a high level, because I think I'm just missing a concept somewhere.

    NetworkLogger *logger = new NetworkLogger();

    AnalyzeMessage *analyzeMessage = new AnalyzeMessage();

    DataGen dataGen = new DataGen();

    QThread *dataGenThread = new QThread();

    What's going on here, "dataGen" is generating some data and when it has the right kind of data, it emits a SIGNAL(dataAvailable(QString)) to "analyzeMessage" SLOT(analyze(QString)). If "analyze" likes the data, it will emit "msgToLog" in order to log it to the "logger" which just makes a network request to a web server using QNetworkAccessManager, QNetworkRequest, and QUrl.

    My problem is, if I emit the SIGNAL from "dataGen" inside it's own thread, the SIGNAL hits the SLOT in "analyze" (at least according to my debug output), but the QNetworkAccessManager never fires off to the web server. If I emit the signal from a dummy class within the same thread as analyze & logger, it works.

    Hope that makes sense. I can post the complete code if that will help to decipher what's going here. Just thought it easier to explain it at a higher level.

  • I figured it out! Mia Culpa!!!

    I forgot to "moveToThread" dataGen before line 12 in the code above.

Log in to reply