Important: Please read the Qt Code of Conduct -

How to handle different responses from QNetworkAccessManager

  • 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.

  • 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.

  • Hi,

    QNetworkReply class is derived from QObject. You can "set properties": 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.

Log in to reply