qwebengine download code example

Example 1: qwebengine download

void MainWindow::downloadRequested(QWebEngineDownloadItem* download) {
        if (download->savePageFormat() != QWebEngineDownloadItem::UnknownSaveFormat)  {
            qDebug() << "Format: " <<  download->savePageFormat();
            qDebug() << "Path: " << download->path();
            // If you want to modify something like the default path or the format
            download->setSavePageFormat(...);
            download->setPath(...);
            // Check your url to accept/reject the download
            download->accept();
        }
}

Example 2: qwebengine download

connect(webView->page()->profile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)),
                this, SLOT(downloadRequested(QWebEngineDownloadItem*)));

Tags: