Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Get Download file Name using QWebEngine



  • Hello,
    I use QWebEngine to view a website, there is a download popup window show up and i need to download it a folder i set i use this code,
    this to get any signal of a download file

        ui->widget->load(QUrl(ui->lineEdit->text().trimmed()));
        QWebEnginePage *page = ui->widget->page();
        QWebEngineProfile *profile = page->profile();
        connect(profile, SIGNAL(downloadRequested(QWebEngineDownloadItem*)), this, SLOT(DownloadItem(QWebEngineDownloadItem*)));
    

    then I do this to start accept and download the file in the slot

    void MainWindow::DownloadItem(QWebEngineDownloadItem *item)
    {
        item->setPath("D:/amr.pdf");
        connect(item, SIGNAL(finished()), this, SLOT(DownloadFinish()));
        connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
        item->accept();
        qDebug() << "URL to download = " << item->url().toString();
    }
    

    The trick here is after the I download the file, there is a javascript file shows up and ask me to name the file, so the question here how can i get the file name wrote in this javascript dialog, here is an image of how it looks like
    alt text
    so I need a way to get the file name in the slot or anything so i can use this to take this name and name the file before i press ok and the download start.

    Thanks.



  • @AmrCoder
    Have you looked at https://doc.qt.io/qt-5/qwebenginedownloaditem.html#path ?

    The trick here is after the I download the file, there is a javascript file shows up and ask me to name the file

    so I need a way to get the file name in the slot or anything so i can use this to take this name and name the file before i press ok and the download start.

    Seems to be incompatibility in above two sentences: either the prompt shows before you save to file or after, not both!


Log in to reply