Web request with progress bar - c++

This is my code (C++: Qt) for getting webpage source:
QString htmlString;
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QNetworkRequest req( QUrl( QString( "http://stackoverflow.com" ) ) );
QNetworkReply *reply = mgr.get(req);
eventLoop.exec();
htmlString = reply->readAll();
Is there any way to get webpage source with progress bar ?!

Write special class for this:
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QDebug>
#include <QProgressBar>
class Downloader : public QObject
{
Q_OBJECT
public:
explicit Downloader(QObject *parent = 0);
void doDownload();
public slots:
void replyFinished (QNetworkReply *reply);
void updateDownloadProgress(qint64, qint64);
private:
QNetworkAccessManager *manager;
QProgressBar *bar;
};
#endif
Cpp:
Downloader::Downloader(QObject *parent) :
QObject(parent)
{
}
void Downloader::doDownload()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
QNetworkReply * rep = manager->get(QNetworkRequest(QUrl("http://qt-project.org/")));
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(updateDownloadProgress(qint64, qint64)));
bar = new QProgressBar;
bar->show();
}
void Downloader::replyFinished (QNetworkReply *reply)
{
if(reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else
{
qDebug() << reply->readAll();
}
reply->deleteLater();
}
void Downloader::updateDownloadProgress(qint64 read, qint64 total)
{
qDebug() << read << total;
bar->setMaximum(total);
bar->setValue(read);
}
Usage:
Downloader down;
down.doDownload();
Main idea here is to use void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) [signal] to get progress and show this progress in QProgressBar.
And you can do this with your current code without class:
QString htmlString;
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QProgressBar *bar = new QProgressBar;
bar->show();
QNetworkRequest req( QUrl( QString( "http://stackoverflow.com" ) ) );
QNetworkReply *reply = mgr.get(req);
QObject::connect(reply,&QNetworkReply::downloadProgress,[=](qint64 bytesReceived, qint64 bytesTotal) {//with lambda
bar->setMaximum(bytesTotal);
bar->setValue(bytesReceived);
});
eventLoop.exec();
htmlString = reply->readAll();
qDebug() << htmlString;
I used here C++11 (CONFIG += c++11 to .pro file) and new syntax of signals and slots.

Related

QCompleter doesn't work properly with NetworkRequest finished

Qcompleter which is associated with a lineEdit doesn't work in the slot of a QNetworkRequest finished.The Qcompleter disappeared quite quickly.Each time the text in lineEdit changed a request was send.I tried a demo without other code,it also occured.
Every time the text in lineEdit was edit,a request contains the text will be send to my server.And then I want to show the content in reply in a Qcompleter.But the prompt disappears in a instant.
void MainWindow::onRequestFinished(QNetworkReply* reply){
QStringList stringList;
stringList << "test1" <<"test2"<<"test3";
QCompleter* completer = new QCompleter(stringList,this);
completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
ui->lineEdit->setCompleter(completer);
reply->deleteLater();
}
void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
QUrl url("http://www.google.com");
QNetworkRequest request;
request.setUrl(url);
manager->get(request);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
...
this->manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onRequestFinished(QNetworkReply*)));
...
}
The logic is similar to an old answer of mine, in it a model is created that will store the information this prevents you from creating a QCompleter at every moment avoiding the problem the disappearance of the popup.
#include <QtWidgets>
#include <QtNetwork>
class SuggestModel: public QStandardItemModel
{
Q_OBJECT
public:
using QStandardItemModel::QStandardItemModel;
void search(const QString & text)
{
QNetworkRequest request = create_request(text);
if(m_reply)
m_reply->abort();
m_reply = manager.get(request);
connect(m_reply, &QNetworkReply::finished, this, &SuggestModel::onFinished);
QEventLoop loop;
connect(this, &SuggestModel::finished, &loop, &QEventLoop::quit);
loop.exec();
}
private Q_SLOTS:
void onFinished(){
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
QUrl url = reply->url();
if (reply->error() == QNetworkReply::NoError) {
QVector<QString> choices;
QByteArray response(reply->readAll());
QXmlStreamReader xml(response);
while (!xml.atEnd()) {
xml.readNext();
if (xml.tokenType() == QXmlStreamReader::StartElement)
if (xml.name() == "suggestion") {
QStringRef str = xml.attributes().value("data");
choices << str.toString();
}
}
clear();
for(const QString & choice: choices)
appendRow(new QStandardItem(choice));
}
reply->deleteLater();
Q_EMIT finished();
m_reply = nullptr;
}
Q_SIGNALS:
void finished();
private:
QNetworkRequest create_request(const QString & text){
const QString suggestUrl(QStringLiteral("http://google.com/complete/search?output=toolbar&q=%1"));
QString url = suggestUrl.arg(text);
return QNetworkRequest(url);
}
QNetworkAccessManager manager;
QNetworkReply *m_reply = nullptr;
};
class SuggestCompleter: public QCompleter{
public:
SuggestCompleter(QObject *parent=nullptr):
QCompleter(parent)
{
SuggestModel *m_model = new SuggestModel(this);
setModel(m_model);
setCompletionMode(QCompleter::UnfilteredPopupCompletion);
}
QStringList splitPath(const QString &path) const override{
if(SuggestModel * m = qobject_cast<SuggestModel *>(model()))
m->search(path);
return QCompleter::splitPath(path);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLineEdit le;
le.setCompleter(new SuggestCompleter(&le));
le.show();
return a.exec();
}
#include "main.moc"

Qt execute multiple get with QNetworkAccessManager

I have to execute a lot of get requests and they have to be hadled in different ways. So far, I have this simply approach that works:
And here's the code for .h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void finish(QNetworkReply *reply);
void finish2(QNetworkReply *reply);
private:
Ui::MainWindow *ui;
QNetworkAccessManager* manager;
};
#endif // MAINWINDOW_H
And code for .cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
//First request here...
void MainWindow::on_pushButton_clicked()
{
manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, this, &MainWindow::finish);
manager->get(QNetworkRequest{QUrl{"http://www.link.com/path/"}});
}
//... is completed here
void MainWindow::finish(QNetworkReply *reply) {
if (reply->error()) {
ui->lineEdit->setText("error");
qDebug() << reply->errorString();
} else {
ui->lineEdit->setText(QString{reply->readAll()});
}
}
//Second request here...
void MainWindow::on_pushButton_2_clicked()
{
manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, this, &MainWindow::finish2);
manager->get(QNetworkRequest{QUrl{"https://ergast.com/api/f1/2008/5.json"}});
qDebug() << "chiamata";
}
//... is completed here
void MainWindow::finish2(QNetworkReply *reply) {
if (reply->error()) {
ui->lineEdit_2->setText("error");
qDebug() << reply->errorString();
} else {
ui->lineEdit_2->setText(QString{reply->readAll()});
}
}
When I press both buttons the requests happen but my UI blocks. I have tried this approach because I have seen in many examples that it's good to have a QNetworkAccessManager* manager; as private field and re-use it.
It does not seem by the way the best approach. Is there a proper way to do multiple calls?
Should I declare maybe an array of QNetworkAccessManager* and execute there all the calls?
I have also seen that there's the possibility to create a private field called QNetworkReply* reply; and then use it like this:
manager = new QNetworkAccessManager(this);
reply = manager->get(QNetworkRequest{QUrl{"http://www.link.com/path/"}});
connect(manager, &QNetworkReply::finished, this, &MainWindow::finish);
I think that this is equivalent to the method I am using but in this case I don't know how to handle multiple requests because I am bind to the finish method and I should implement all the logic there.
I have tested your code and I have not noticed that the GUI is blocked, in addition to using signals and slots you should not have that problem. However I see that you are creating dynamic memory unnecessarily, in the following code I connect the QNetworkReply to a slot, filter through the QUrl and delete the QNetworkReply:
*.h
...
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void onReplyfinished();
private:
Ui::MainWindow *ui;
QNetworkAccessManager *manager;
...
*.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
manager = new QNetworkAccessManager(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QNetworkReply *reply = manager->get(QNetworkRequest{QUrl{"http://www.link.com/path/"}});
connect(reply, &QNetworkReply::finished, this, &MainWindow::onReplyfinished);
}
void MainWindow::on_pushButton_2_clicked()
{
QNetworkReply *reply = manager->get(QNetworkRequest{QUrl{"https://ergast.com/api/f1/2008/5.json"}});
connect(reply, &QNetworkReply::finished, this, &MainWindow::onReplyfinished);
}
void MainWindow::onReplyfinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if(reply->url() == QUrl{"http://www.link.com/path/"}){
ui->lineEdit->setText(reply->error() ? "error": reply->readAll());
}
else if (reply->url() == QUrl{"https://ergast.com/api/f1/2008/5.json"}){
ui->lineEdit_2->setText(reply->error() ? "error": reply->readAll());
}
reply->deleteLater();
}

How to make a post request to API Rest in Qt?

I wrote a piece of code that sends me, via a post request, a json to my API Rest; and works!
main.cpp
void replyFinished(QNetworkReply *reply)
{
reply->deleteLater();
qDebug() << "reply delete!";
qDebug() << "https post_request done!";
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkAccessManager *manager = new QNetworkAccessManager();
QUrl url("https://.../");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QObject::connect(manager, &QNetworkAccessManager::finished, replyFinished);
quint8 speed = 0x12;
quint8 accelleration = 0x2b;
QString json = QString("{\"speed\":\"%1\",\"acceleration\":\"%2\"}").arg(speed).arg(accelleration);
manager->post(request, json.toUtf8());
return a.exec();
}
But when I want to integrate this piece of code in my program, it does not work. Briefly, my program gets through the SIGNAL and SLOT mechanism, a QByteArray, from which I take the data and I send them to my API Rest.
This is my Header.h
...
class Packet : public QObject
{
Q_OBJECT
public:
Packet();
public slots:
void receivePayload(QByteArray &bufferToJson);
void replyFinished(QNetworkReply *reply);
private:
QNetworkAccessManager *m_manager;
quint8 m_speed;
quint8 m_accelleration;
public:
QString json;
};
...
This is my class.cpp
Packet::Packet()
: m_manager { new QNetworkAccessManager }
{
QObject::connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
void Packet::replyFinished(QNetworkReply *reply)
{
reply->deleteLater();
qDebug() << "reply delete!";
qDebug() << "https post_request done!";
}
void Packet::receivePayload(QByteArray &bufferToJson){
m_speed = bufferToJson.at(0);
m_accelleration = bufferToJson.at(1);
QUrl url("https://.../");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QString json = QString("{\"speed\":\"%1\",\"acceleration\":\"%2\"}").arg(m_speed).arg(m_accelleration);
m_manager->post(request, json.toUtf8());
}
What's the problem of my change?

Qt QNetworkAccessManager and Slot not working

i am a beginner in c++ and i am trying to retrieve data from a website using http request and to download the data in a file .
I am using the classes :
QMainWindow
QtNetwork/QNetworkAccessManager
QtNetwork/QNetworkRequest
QtNetwork/QNetworkReply
QUrl
The thing is that the file is created but there is no data in the file and i am getting an error that i don't understand . I searched through the forum found some similar kind of problems but did not understand as i am a beginner . Please help me its a school project and i am really stuck here.
Here is the httpWindow.h code
#ifndef HTTPWINDOW_H
#define HTTPWINDOW_H
#include <QMainWindow>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QUrl>
#include <QString>
class QFile;
namespace Ui {
class httpWindow;
}
class httpWindow : public QMainWindow
{
Q_OBJECT
public:
explicit httpWindow(QWidget *parent = 0);
~httpWindow();
void request(QUrl url);
private slots:
void downloadFile();
void httpFinished();
void httpReadyRead();
private:
Ui::httpWindow *ui;
QUrl url;
QNetworkAccessManager *manager;
QNetworkRequest requete;
QNetworkReply *reply;
QFile *file;
int httpGetId;
bool httpRequestAborted;
};
#endif // HTTPWINDOW_H
Here is the httpwindow.cpp
#include <QtWidgets>
#include <qnetwork.h>
#include <QString>
#include "httpwindow.h"
#include "ui_httpwindow.h"
httpWindow::httpWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::httpWindow)
{
ui->setupUi(this);
downloadFile();
}
httpWindow::~httpWindow()
{
delete ui;
}
void httpWindow::request(QUrl url)
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished()),
this, SLOT(httpFinished()));
//requete.setUrl(QUrl("http://fxrates.fr.forexprostools.com/index.php?force_lang=5&pairs_ids=1;3;2;4;7;5;8;6;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&bid=show&ask=show&last=show&change=hide&last_update=hide"));
requete.setUrl(url);
reply = manager->get(requete);
connect(reply, SIGNAL(&reply::readyRead()), this, SLOT(httpReadyRead()));
}
void httpWindow::downloadFile()
{
QMessageBox msg ;
QUrl url("http://fxrates.fr.forexprostools.com/index.php?force_lang=5&pairs_ids=1;3;2;4;7;5;8;6;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&bid=show&ask=show&last=show&change=hide&last_update=hide") ;
qDebug() << url.toString();
QFileInfo fileInfo(url.path());
//msg.setText("fileInfo = " + fileInfo);
QString fileName = "C:\\testQt\\" + fileInfo.fileName();
msg.setText("fileName = " + fileName);
if (fileName.isEmpty()){
fileName = "C:\testQt\fichier.html";
msg.setText(" création d'un nouveau fichier fichier.html ");
}
if (QFile::exists(fileName)) {
QFile::remove(fileName);
return;
}
file = new QFile(fileName);
msg.setText(" QFile::exists(fileName) == true , file : ");
if (!file->open(QIODevice::WriteOnly)) {
delete file;
file = 0;
return;
}
// schedule the request
httpRequestAborted = false;
request(url);
}
void httpWindow::httpFinished()
{
if (httpRequestAborted) {
if (file) {
file->close();
file->remove();
delete file;
file = 0;
}
reply->deleteLater();
return;
}
file->flush();
file->close();
QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (reply->error()) {
file->remove();
// QMessageBox::information(this, tr("HTTP"),
// tr("Download failed: %1.")
// .arg(reply->errorString()));
// downloadButton->setEnabled(true);
} else if (!redirectionTarget.isNull()) {
QUrl newUrl = url.resolved(redirectionTarget.toUrl());
// if (QMessageBox::question(this, tr("HTTP"),
// tr("Redirect to %1 ?").arg(newUrl.toString()),
// QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
url = newUrl;
reply->deleteLater();
file->open(QIODevice::WriteOnly);
file->resize(0);
request(url);
return;
}
reply->deleteLater();
reply = 0;
delete file;
file = 0;
}
void httpWindow::httpReadyRead()
{
// this slot gets called every time the QNetworkReply has new data.
// We read all of its new data and write it into the file.
// That way we use less RAM than when reading it at the finished()
// signal of the QNetworkReply
if (file)
file->write(reply->readAll());
}
Here is the main.cpp code
#include "httpwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
httpWindow w;
w.show();
return a.exec();
}
The errors :
can't find linker symbol for virtual table for `QMessageBox' value
found `RGB_MASK' instead
can't find linker symbol for virtual table for `QMessageBox' value
found `RGB_MASK' instead
"http://fxrates.fr.forexprostools.com/index.php?force_lang=5&pairs_ids=1;3;2;4;7;5;8;6;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&bid=show&ask=show&last=show&change=hide&last_update=hide"
QObject::connect: No such signal QNetworkAccessManager::finished() in ..\ppe3_trading_test\httpwindow.cpp:24
QObject::connect: (receiver name: 'httpWindow')
QObject::connect: No such signal QNetworkReplyHttpImpl::&reply::readyRead() in ..\ppe3_trading_test\httpwindow.cpp:31
QObject::connect: (receiver name: 'httpWindow')
Please do help me its really important for my schooling .
connect(reply, SIGNAL(&reply::readyRead()), this, SLOT(httpReadyRead()));
You're mixing up old syntax and new syntax, it should be
connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
or better yet using new syntax(Qt5 only):
connect(reply, &QNetworkReply::readyRead, this, &httpWindow::httpReadyRead);
QNetworkAccessManager doesn't have a finished() signal it has a finished(QNetworkReply*) signal, read the docs.

Qt NetworkAccessManager finished signal

I have a code that will download a package from the web. I want such code to run a html5viewer (or a window, it will be the same) after the download has finished, meaning I have to handle the finished() signal, here is my code:
main.cpp
#include <QApplication>
#include "html5applicationviewer.h"
#include "networkmanager.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
NetworkManager manager;
//manager.setFile("http://listadomedicamentos.aemps.gob.es/prescripcion.zip");
manager.setFile("http://listadomedicamentos.aemps.gob.es/prescripcion.zip");
/*
Html5ApplicationViewer viewer;
viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
viewer.showMaximized();
viewer.loadFile(QLatin1String("html/index.html"));*/
return app.exec();
}
networkmanager.h
#include <QObject>
#include "html5applicationviewer.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFile>
#include <QStringList>
class NetworkManager : public QObject
{
Q_OBJECT
public:
explicit NetworkManager(QObject *parent = 0);
virtual ~NetworkManager();
void setFile(QString fileURL);
private:
QNetworkAccessManager *manager;
QNetworkReply *reply;
QFile *file;
private slots:
void onDownloadProgress(qint64, qint64);
void onFinished(QNetworkReply *reply);
void onReadyRead();
void onReplyFinished();
};
networkmanager.cpp
#include "networkmanager.h"
#include "html5applicationviewer.h"
#include <QDir>
#include <QStandardPaths>
#include <QDebug>
NetworkManager::NetworkManager(QObject *parent) :
QObject(parent)
{
manager = new QNetworkAccessManager;
}
NetworkManager::~NetworkManager()
{
manager->deleteLater();
}
void NetworkManager::setFile(QString fileURL)
{
QString filePath = fileURL;
QString saveFilePath;
QString savePath;
QStringList filePathList = filePath.split('/');
QString fileName = filePathList.at(filePathList.count() - 1);
savePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
if (QDir(savePath).exists())
{
qDebug() << "Archivos locales para almacenar la base de datos existentes.";
}
else
{
qDebug() << "Creando los archivos locales para almacenar la base de datos...";
QDir().mkdir(savePath);
}
saveFilePath = QString(savePath + "/" + fileName );
QNetworkRequest request;
request.setUrl(QUrl(fileURL));
reply = manager->get(request);
file = new QFile;
file->setFileName(saveFilePath);
file->open(QIODevice::WriteOnly);
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this,
SLOT(onDownloadProgress(qint64,qint64)));
connect(manager, SIGNAL(finished(QNetworkReply*)), this,
SLOT(onFinished(QNetworkReply*)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
}
void NetworkManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal)
{
qDebug() << QString::number(bytesRead).toLatin1() + " bytes descargados de " +
QString::number(bytesTotal).toLatin1() + " bytes totales";
}
void NetworkManager::onFinished(QNetworkReply *reply)
{
switch (reply->error())
{
case QNetworkReply::NoError:
{
qDebug() << "El archivo se ha descargado con éxito.";
}
break;
default:
qDebug() << reply->errorString().toLatin1();
}
if (file->isOpen())
{
file->close();
file->deleteLater();
}
}
void NetworkManager::onReadyRead()
{
file->write(reply->readAll());
}
void NetworkManager::onReplyFinished()
{
if (file->isOpen())
{
file->close();
file->deleteLater();
}
}
I have tried doing
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished(Html5ApplicationViewer&)));
void NetworkManager::onReplyFinished(Html5ApplicationViewer &viewer)
{
viewer.show();
if (file->isOpen())
{
file->close();
file->deleteLater();
}
}
But it will tell me that:
QObject::connect: Incompatible sender/receiver arguments
QNetworkReplyHttpImpl::finished() --> NetworkManager::startViewer(Html5ApplicationViewer&)
How could I make this viewer or window start with that finished() signal?
You are facing issue because, QNetworkAccessManager's finished signal does not have any parameter while you are connecting it with slot which takes Html5ApplicationViewer as parameter.
which is not compatible and thus you are getting warning.
If you want to have access to Html5ApplicationViewer pointer then you will need to assign or create pointer inside your NetworkManager class.