Solved QWebEngineProfile downloadRequested() not invoking
-
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(QWebEngineDownloadItem* 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());
-
Hello @bandito
I tested your code on Qt 5.12.2 and everthing is working well with a single change.
webPageDownload->download(QString("https://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download"), "file.cvs");
Because QUrl cannot use const char* variable as parameter and don't auto convert to QString.
First of all, what Qt and MSVC versions are you using ?
-
This may sound weird but I play around with it some more and it was calling another method. I changed some of the code in that method and then downloadRequested got called. I guess something went squirrelly in the QT engine.