Qt6.7 Drag and Drop on WebAssembly
-
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?
-
@PEPSoares QFile takes a path, not an URL. Convert your URL to a path.
-
@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
-
@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 triedQFile("//qt/tmp/something")
withexists()
&open()
to make sure that works? -
@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... -
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"
-
@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
.