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. List of HTTP Requests
Qt 6.11 is out! See what's new in the release blog

List of HTTP Requests

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

    Hi everyone, I will explain my problem

    I have a simple class to manage the picture downloads and looks like:

    @

    void NetworkHandler::getImage(QString name, const QObject *amember, const char * atype, const char * atype2){
    QNetworkAccessManager * http = new QNetworkAccessManager();
    reply = http->get(QNetworkRequest(QUrl(name)));
    connect(reply, SIGNAL(finished()), amember, atype);
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), amember, atype2);
    }

    QByteArray NetworkHandler::readData() {
    return reply->readAll();
    }

    @

    It works perfectly for one picture, but the problem comes when I want to download more than one, it crashes because I'm using the QNetworkReply object for the first one. I could build another class but I want to do it generic.

    I tried including another QNetworkReply object for each call but it doesn't work, I don't know why.

    Does anyone knows what can I do?

    Thanks in advance.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Use sender() in your slot?

      (And watch out: you're leaking memory for your QNAM objects, and that's a bad use case -- build only one QNAM for your application and use it for all your requests).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • J Offline
        J Offline
        javiyt
        wrote on last edited by
        #3

        Hi, sorry for the late response.

        I solved the problem you told me and I built just one QNAM to manage the requests. I have a special class managing the network requests with a post method and a readData method as I wrote in the last message.

        It uses just one QNetworkReply to get the answer of the request. What will happend when I make two asynchronous requests in a row and the second one is thrown before the first one comes back?

        Do I have to create a list of QNetworkReplys to manage it?

        Thank you a lot!

        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