Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get Download file Name using QWebEngine
Forum Updated to NodeBB v4.3 + New Features

Get Download file Name using QWebEngine

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 395 Views 1 Watching
  • 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • AmrCoderA AmrCoder

      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.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @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!

      1 Reply Last reply
      0

      • Login

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