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. QNetworkAccessManager make another request after response

QNetworkAccessManager make another request after response

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 221 Views 2 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.
  • P Offline
    P Offline
    Pedro Vicente
    wrote on last edited by
    #1

    I have a QNetworkAccessManager instance

    https://doc.qt.io/qt-6/qnetworkaccessmanager.html

    m_network = new QNetworkAccessManager(this);
    connect(m_network, &QNetworkAccessManager::finished, this, &LabelEntry::on_finished);
    

    that requests an URL.
    example : http://100.36.4.152/index.html

    the response is obtained in a QLabel class and in it I extract this URL, like this

    void LabelEntry::on_finished(QNetworkReply* reply)
    {
      QNetworkRequest request = reply->request();
      QUrl url = request.url();
      QString path = url.path();
      QString url_path = url.url();
      QString url_main = url_path.remove(path);
    
      QByteArray data = reply->readAll();
      QString html = QString(data);
    

    this prints for url_main

    http://100.36.4.152

    and variable 'html' has the HTML buffer

    Next, I am going to extract the HTML tags from this buffer (irrelevant how to do it for this);

    http://100.36.4.152/index.html

    I obtained, that the HTML has an image tag in it, for example

    icons/ubuntu-logo.png

    so, the complete URL of this image is

    http://100.36.4.152/icons/ubuntu-logo.png

    Now, I need to get this image.

    Question , what would be the best way to do it?
    This was already obtained in a QNetworkAccessManager instance, so, one way, would be to define yet another for this request ? and where to define and call it, from the Qt frameworkt?
    locally from this class (LabelEntry), or define another class for the new request ?

    Gracias

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Use the same QNAM, however rather than connecting its finished signal, do it for the reply of your request so you can properly handle the two request independently.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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