Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Qt6.7 Drag and Drop on WebAssembly

Qt6.7 Drag and Drop on WebAssembly

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
7 Posts 3 Posters 1.4k 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.
  • P Offline
    P Offline
    PEPSoares
    wrote on last edited by
    #1

    Hi,
    I need a webassembly app that opens a file and uploads it's data to a CouchDb server via PUT.

    Using QFileDialog::getOpenFileContent() I was able to this but the drawback is that I can only do it one file at a time.

    Qt6.7 Now allows for Drag and drop events to be received.
    I now received on the drop event something like [file:///qt/tmp/qebM8Nmr7Ok.jpg] which can be used as a source to a qml Image the problem is that I cannot use that source "qt/tmp/qebM8Nmr7Ok.jpg" to open a QFile. both QFile::exists() and open() return false;

     QFile *file = new QFile(path);
     qDebug() << "Exists "  << file->exists();  // always false
    
     //obviously fails since exists() returns false
     if(!file->open(QFile::ReadOnly)) 
      {
           qDebug() << "Error uploading file: " << path << file->error();  
           //error 5 QFileDevice::OpenError
    } 
    

    Is this possible? Am I doing something wrong?

    Christian EhrlicherC 1 Reply Last reply
    0
    • P PEPSoares

      Hi,
      I need a webassembly app that opens a file and uploads it's data to a CouchDb server via PUT.

      Using QFileDialog::getOpenFileContent() I was able to this but the drawback is that I can only do it one file at a time.

      Qt6.7 Now allows for Drag and drop events to be received.
      I now received on the drop event something like [file:///qt/tmp/qebM8Nmr7Ok.jpg] which can be used as a source to a qml Image the problem is that I cannot use that source "qt/tmp/qebM8Nmr7Ok.jpg" to open a QFile. both QFile::exists() and open() return false;

       QFile *file = new QFile(path);
       qDebug() << "Exists "  << file->exists();  // always false
      
       //obviously fails since exists() returns false
       if(!file->open(QFile::ReadOnly)) 
        {
             qDebug() << "Error uploading file: " << path << file->error();  
             //error 5 QFileDevice::OpenError
      } 
      

      Is this possible? Am I doing something wrong?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @PEPSoares QFile takes a path, not an URL. Convert your URL to a path.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      P 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @PEPSoares QFile takes a path, not an URL. Convert your URL to a path.

        P Offline
        P Offline
        PEPSoares
        wrote on last edited by
        #3

        @Christian-Ehrlicher ~
        Thanks for replying
        I am not using the URL on QFile I am converting it (I might be missing something......)

        Here is a simple test.

        //QML
         onDropped: function (drag) {
                    var urls = drag.urls; 
                    console.log("urls: ", urls) // urls:  [file:///qt/tmp/hrliUZNhpww.jpg]
                    ...........
        
        //cpp
        .....
            qDebug() << "....." << fileUrl; // QUrl("file:////qt/tmp/hrliUZNhpww.jpg")
            qDebug() << "....." << fileUrl.path(); //  "//qt/tmp/hrliUZNhpww.jpg"
            qDebug() << "....." << fileUrl.fileName(); // "hrliUZNhpww.jpg"
            qDebug() << "....." << fileUrl.isLocalFile(); // true
            qDebug() << "....." << fileUrl.toLocalFile(); // "//qt/tmp/hrliUZNhpww.jpg"
            file2 = new QFile(fileUrl.path());
            qDebug() << "F2" << file2->exists(); // false
            qDebug() << "F2O" << file2->open(QFile::ReadOnly); // false
            file2 = new QFile(fileUrl.toLocalFile()); 
            qDebug() << "F2" << file2->exists(); // false
            qDebug() << "F2O" << file2->open(QFile::ReadOnly); // false
        .....
        
        

        Am I converting it wrong and sending the wrong path to QFIle?

        Thanks

        JonBJ 1 Reply Last reply
        0
        • P PEPSoares

          @Christian-Ehrlicher ~
          Thanks for replying
          I am not using the URL on QFile I am converting it (I might be missing something......)

          Here is a simple test.

          //QML
           onDropped: function (drag) {
                      var urls = drag.urls; 
                      console.log("urls: ", urls) // urls:  [file:///qt/tmp/hrliUZNhpww.jpg]
                      ...........
          
          //cpp
          .....
              qDebug() << "....." << fileUrl; // QUrl("file:////qt/tmp/hrliUZNhpww.jpg")
              qDebug() << "....." << fileUrl.path(); //  "//qt/tmp/hrliUZNhpww.jpg"
              qDebug() << "....." << fileUrl.fileName(); // "hrliUZNhpww.jpg"
              qDebug() << "....." << fileUrl.isLocalFile(); // true
              qDebug() << "....." << fileUrl.toLocalFile(); // "//qt/tmp/hrliUZNhpww.jpg"
              file2 = new QFile(fileUrl.path());
              qDebug() << "F2" << file2->exists(); // false
              qDebug() << "F2O" << file2->open(QFile::ReadOnly); // false
              file2 = new QFile(fileUrl.toLocalFile()); 
              qDebug() << "F2" << file2->exists(); // false
              qDebug() << "F2O" << file2->open(QFile::ReadOnly); // false
          .....
          
          

          Am I converting it wrong and sending the wrong path to QFIle?

          Thanks

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @PEPSoares said in Qt6.7 Drag and Drop on WebAssembly:

          qDebug() << "....." << fileUrl.path(); // "//qt/tmp/hrliUZNhpww.jpg"

          So you try to open //qt/tmp/hrliUZNhpww.jpg. I am not saying this is wrong, but the leading // is "unusual". You have not said what platform you are on. Can you see a directory accessible via //qt/tmp? Have you tried QFile("//qt/tmp/something") with exists() & open() to make sure that works?

          P 1 Reply Last reply
          0
          • JonBJ JonB

            @PEPSoares said in Qt6.7 Drag and Drop on WebAssembly:

            qDebug() << "....." << fileUrl.path(); // "//qt/tmp/hrliUZNhpww.jpg"

            So you try to open //qt/tmp/hrliUZNhpww.jpg. I am not saying this is wrong, but the leading // is "unusual". You have not said what platform you are on. Can you see a directory accessible via //qt/tmp? Have you tried QFile("//qt/tmp/something") with exists() & open() to make sure that works?

            P Offline
            P Offline
            PEPSoares
            wrote on last edited by
            #5

            @JonB
            Hi,
            I know "//" might be wrong but I have no idea what the path should be...
            I am on Qt6.7 WebAssembly multi-threaded.
            I'll try to use QDir to check the path....

            An image in Qml can access "file:////qt/tmp/hrliUZNhpww.jpg" so it must be there....

            I am either sending the wrong path to QFile or QFile has no access to this dir the way I am using it.

            I did not create that directory, from what I understand it was created by Qt or Emscripten temporally in the sandboxed filesystem..
            For example, If you try to open a QFileDialog in web assembly you will see a sandbox filesystem product of emscripten...

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PEPSoares
              wrote on last edited by
              #6

              Well...... I guess I found the "problem".
              QFile cannot open the file because the file does not exist....
              I remembered to check with QFileDialog the sandbox filesystem.... there was a "qt" folder with a "tmp" but no file inside.

              So how can qml Image access it?..... Apparently you can indeed set source: "received url" but only once.... if you do something like:

              image.source = url;
              lastUrl = url;
              
              //wait some time 
              
              image.source = "";
              image.source = lastUrl;
              
              

              Image will fail to open the url.

              So...
              How are files handled? They are copied but then immediately deleted? Is there any way I can control this?

              Btw: QDir can access "/qt/tmp"

              JonBJ 1 Reply Last reply
              0
              • P PEPSoares

                Well...... I guess I found the "problem".
                QFile cannot open the file because the file does not exist....
                I remembered to check with QFileDialog the sandbox filesystem.... there was a "qt" folder with a "tmp" but no file inside.

                So how can qml Image access it?..... Apparently you can indeed set source: "received url" but only once.... if you do something like:

                image.source = url;
                lastUrl = url;
                
                //wait some time 
                
                image.source = "";
                image.source = lastUrl;
                
                

                Image will fail to open the url.

                So...
                How are files handled? They are copied but then immediately deleted? Is there any way I can control this?

                Btw: QDir can access "/qt/tmp"

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @PEPSoares said in Qt6.7 Drag and Drop on WebAssembly:

                QFile cannot open the file because the file does not exist....

                That does not surprise me. One would assume that the file is clearly a temporary file, valid somehow during the drag & drop, then removed. That is why I asked only if you could access the directory, not the file.

                Btw: QDir can access "/qt/tmp"

                The question was for //qt/tmp, not /qt/tmp.

                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