Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineProfile downloadRequested() not invoking

QWebEngineProfile downloadRequested() not invoking

Scheduled Pinned Locked Moved Solved QtWebEngine
3 Posts 2 Posters 1.2k Views
  • 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.
  • banditoB Offline
    banditoB Offline
    bandito
    wrote on last edited by
    #1

    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());
    
    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      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 ?

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      1
      • banditoB Offline
        banditoB Offline
        bandito
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        1

        • Login

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