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]Multiple requests using QNetworkAccessManager
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Multiple requests using QNetworkAccessManager

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

    Hello!

    I need to send 5 requests to a site which replies for me a image file. I am using the reply to add the image to a pixmap, then adding it to a new QList<QLabel *> item. The problem is that if I use any kind of loop it blocks (for loop from 0 to 4, while(timer.isActive()). I think I managed to send the requests using a recursive way (call a function in the constructor of the class, I have a slot for reply->finished(), and in the slot I call the function again with the new parameters) but now it locks when I add the QLabels from my list to the windows I want to display... Don't know if it blocks because of the requests or the function for adding the layout... Can anyone help?

    Class inherits QWidget.

    @void Class::addLayout() {
    QVBoxLayout *lay = new QVBoxLayout();
    for(int i = 0; i < list.size(); i++) {
    lay->addWidget(list.at(i));

    }
    this->setLayout(lay);
    this->show();
    }
    @

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HIskind
      wrote on last edited by
      #2

      I don't think it's blocks because of requests:
      "Here":http://qt-project.org/doc/qt-4.8/QNetworkAccessManager.html#details saids:

      bq. QNetworkAccessManager queues the requests it receives. The number of requests executed in parallel is dependent on the protocol. Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination.

      I've tried to run your method addLayout and it works correctly only once, the second call generate warning:
      @QWidget::setLayout: Attempting to set QLayout "" on Class "", which already has a layout@
      and nothing happens. That means that new widgets should be added for alredy existed layout (by this->layout() method), instead of creating new.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on last edited by
        #3

        Well... I call the add layout after all the list is loaded (it says it creates a list of labels with size 11, 5 images and 6 with text, which is exactly what I need), thus I create the new layout only once... I think I'm loading the pixmaps wrong... Because when I just try to show a image label my program crashes... Tried with just one network request and it loads the pixmap ok. I am using something like:

        @ QLabel *label = new QLabel();
        QPixmap *pix = new QPixmap();
        pix->loadFromData(netReply->readAll());
        label->setPixmap(pix);
        list << label;
        delete pix;
        delete label; // so I can create new ones for each request@

        As an alternative solution, I'm trying to load the images in a QTextBrowser (because I need them clickable) but I can't seem to get the html tag to load my image from the URL.

        @textBrowser->insertHtml("<img src="url">@

        and it gives me an error:
        @QFSFileEngine::open: No file name specified@

        1 Reply Last reply
        0
        • H Offline
          H Offline
          HIskind
          wrote on last edited by
          #4

          @list << label;
          delete pix;
          delete label; // so I can create new ones for each request@

          Note that list doesn't create a copy of label, it just stores pointer to it. So, when you delete label, your pointer in list becomes broken.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            b1gsnak3
            wrote on last edited by
            #5

            removing the deletes worked. thank you :)

            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