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. How to handle different responses from QNetworkAccessManager
Forum Updated to NodeBB v4.3 + New Features

How to handle different responses from QNetworkAccessManager

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.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.
  • Q Offline
    Q Offline
    quadrilateral
    wrote on last edited by
    #1

    I'm still really new to QT and I'm figuring some stuff out, but I think I have a fairly high-level understanding of signals and slots to explain my problem.

    I'm working with QNetworkAccessManager, I've been using using it to send RESTful requests to our ticketing system. I then get the response from our system, I parse the JSON and map it to my C++ class. The problem I'm having now, is that I need to do some more complicated things, like traverse tickets to get linked tickets, linked tickets of tickets, etc.

    This is fine when I'm in a single thread, because I can merely perform the restful requests iteratively (or recursively) and link them to the original object as I iterate.

    The problem I'm having is that I don't know how to differentiate requests I've sent. For example, I have the initial request for a ticket, I can then get the linked tickets and do individual requests for each linked ticket, but once those requests get sent to my SLOT, I don't know how to differentiate the secondary and tertiary requests from the original request.

    I can elaborate more if this explanation isn't clear enough, but I'd be willing to bet that I'm not the qt-newbie that doesn't know how to handle this. All help is greatly appreciated, thank you.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Here are some thoughts/options:

      • Keep a map of QNetworkReply* to parent ticket id that you insert into at request time and extract from at response time.
      • Inspect the QNetworkRequest that is delivered with the QNetworkReply. That request should be able to carry a QNetworkRequest::User attribute that is the parent ticket id or the like.
      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckakman
        wrote on last edited by
        #3

        Hi,

        QNetworkReply class is derived from QObject. You can "set properties":http://doc.qt.io/qt-5/qobject.html#setProperty on the QNetworkReply. The property doesn't have to exist beforehand. You just can set a new property. You can devise a "tracking" mechanism this way.

        1 Reply Last reply
        0

        • Login

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