Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QNetworkAccessManager/QThread/Signals & Slots
Forum Updated to NodeBB v4.3 + New Features

[Solved] QNetworkAccessManager/QThread/Signals & Slots

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shorawitz
    wrote on 27 Dec 2011, 20:04 last edited by
    #1

    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();
    logger->setup(logHost);

    AnalyzeMessage *analyzeMessage = new AnalyzeMessage();
    QObject::connect(analyzeMessage,SIGNAL(msgToLog(QString)),logger,SLOT(logMsg(QString)));

    DataGen dataGen = new DataGen();
    QObject::connect(dataGen,SIGNAL(dataAvailable(QString),analyzeMessage,SLOT(analyze(QString)));

    QThread *dataGenThread = new QThread();
    dataGenThread->connect(dataGenThread,SIGNAL(started(),dataGen,SLOT(startGen()));
    dataGenThread->start();
    @

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shorawitz
      wrote on 28 Dec 2011, 11:47 last edited by
      #2

      I figured it out! Mia Culpa!!!

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

      1 Reply Last reply
      0

      2/2

      28 Dec 2011, 11:47

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved