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