PDA

View Full Version : QWebEngineProfile downloadRequested() not invoking



bandito
19th April 2019, 19:31
For what ever reason can't get QWenEngineProfile to invoke downloadRequest when downloading a file with QWebEnginePage. The way I understand it is that when QWebEnginePage::download() is called the QWebEningeProfile::downloadRequested() signal is emitted but for some reason my code doesn't catch the signal.

mainwindow.ccp


WebPageDownload *webPageDownload = new WebPageDownload(this);
webPageDownload->download("https://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download", "file.cvs");

webpagedownload.cpp



WebPageDownload::WebPageDownload(QObject *parent){
page = new QWebEnginePage(parent);
connect(page->profile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)) , this, SLOT(downloadRequested(QWebEngineDownloadItem*)));
}

void WebPageDownload::download(const QUrl &url, const QString &filename){
qDebug()<<"download called";
//this should emit QWebEngineProfile::downloadRequested
page->download(url, filename);
}

void WebPageDownload::downloadRequested(QWebEngineDownl oadItem* download) {
qDebug()<<"Download request invoked";
}

webpagedownload.h


class WebPageDownload : public QObject{
Q_OBJECT

public:
WebPageDownload(QObject *parent = nullptr);

private:
QWebEnginePage *page;

private slots:
void downloadRequested(QWebEngineDownloadItem* download);

public slots:
void download(const QUrl &url, const QString &filename = QString());

anda_skoa
20th April 2019, 12:09
This looks correct but just to be sure check the return value of the connect() call.

In any case also have a look at QNetworkAccessManager if you don't need to display the web content.

Cheers,
_