Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Changing downloadDirectory property of WebEngineDownloadItem in QML QtQuick 2.2 and QtWebEngine 1.10
Qt 6.11 is out! See what's new in the release blog

Changing downloadDirectory property of WebEngineDownloadItem in QML QtQuick 2.2 and QtWebEngine 1.10

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 706 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.
  • S Offline
    S Offline
    Sheetal Deshpande
    wrote on last edited by
    #1

    Hi ,
    I am running the webengine\quicknanobrowser example from qt installer for
    5.14.1 version.
    Here I want to change the download directory of downloadItem received in
    signal handler onDownloadRequested.
    If I hard code it to some folder then it works but I want to use a folder
    dialog to browse the folder and then set it to download.downloadDirectory.
    Here is what I tried but not working.

    FolderDialog {
    id: folderDialog
    onAccepted: {
    console.log("\n\nfolder picked");
    }
    }
    function onDownloadRequested(download) {
    folderDialog.open();
    if(folderDialog.result === Dialog.Accepted)
    {
    download.downloadDirectory = folderDialog.folder;
    console.log("$$\nnew dir: " +
    download.downloadDirectory);
    downloadView.append(download);
    download.accept();
    }
    }
    

    So it seems execution of the signal handler function continues after
    folderDialog.open() and once it is complete then it opens the dialog for
    browsing.
    How can execution of onDownloadRequested wait till the user browses folder?

    I tried using timer too like below but again not working:

    
    Timer {
    id: delaytimer;
    interval: 10000;
    running: false;
    repeat: false;
    onTriggered:
    {
    console.log("%%%\n\onTriggered");
    if(folderDialog.result === Dialog.Accepted)
    {
    console.log("%%%\n\done picking");
    folderPicked = true;
    delaytimer.running = false;//stop();
    }
    }
    }
    function onDownloadRequested(download) {
    folderDialog.open();
    delaytimer.running = true;
    while(delaytimer.running == true)
    {
    if(folderPicked == true)
    {
    download.downloadDirectory = folderDialog.folder;
    downloadView.visible = true;
    downloadView.append(download);
    download.accept();
    }
    }
    

    So we want to browse folder and select that folder as download
    directory(override default download directory).

    Can anyone please suggest if we can achieve this and how?

    Thanks in advance.
    Sheetal

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sheetal Deshpande
      wrote on last edited by
      #2

      If anyone comes here for solution, please read below reply from QT support team which I got.

      You need to block the execution in the handler until the
      download location has been set.
      Like below:
      In BrowserWindow.qml

      import Test 1.0
      
          FileDialog {
              id: fd
              selectFolder: true
              property bool done: false
              onAccepted: {
                  done = true
              }
              onRejected: done = true
          }
      
          function onDownloadRequested(download) {
              fd.done = false
              fd.open()
              while(!fd.done) {
                  App.process()
              }
              download.downloadDirectory = App.urlToDir(fd.folder)
              downloadView.visible = true;
              downloadView.append(download);
              download.accept();
          }
      

      In cpp files:

      class App : public QObject
      {
          Q_OBJECT
      public:
          Q_INVOKABLE QString urlToDir(QUrl url)
          {
              return url.toLocalFile();
      
          }
          Q_INVOKABLE void process()
          {
              qApp->processEvents();
          }
      };
      
      int main(int argc, char **argv)
      {
      ///all initialization code and including QApplication creation
          qmlRegisterSingletonInstance("Test", 1, 0, "App", new App);
      }
      

      Regards,
      Sheetal

      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