QFileDialog::getOpenFileContent opens no window
-
As per documentation, I was trying to allow users to select a file with
QFileDialog::getOpenFileContentfrom the browser.
Nothing shows when I do, be it on FireFox or Chrome, but I do get the dialog when I compile for Desktop.To make sure I wasn't the cause of that issue, I tried again on a fresh QML project created from QtCreator (full code at the bottom).
I am having the problem for single and multi-threaded WASM builds.I have found this corrected bug possibly related to my issue, however:
- I am on Qt 6.11.1 (emsdk 4.0.7); I have also tried on Qt6.7.3 (emsdk 3.1.50) with the same result.
Both versions are supposed to be free of that bug. - The working snippet provided by the reporter (setting
nameFilterto"*") does not work.
Is anyone reproducing this issue / able to get the dialog with the code below?
Or would you know what I am doing wrong perhaps?#include <QtWidgets/QApplication> #include <QQmlApplicationEngine> #include <QtWidgets/QFileDialog> int main(int argc, char *argv[]) { QApplication app(argc, argv); auto fileContentReady = [](const QString &fileName, const QByteArray &fileContent) { if (fileName.isEmpty()) { // No file was selected qDebug() << fileName; } else { // Use fileName and fileContent qDebug() << fileName; } QFileInfo fi(fileName); qDebug() << "path: " << fi.path(); }; QFileDialog::getOpenFileContent("*", fileContentReady); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("wasm", "Main"); return QCoreApplication::exec(); } - I am on Qt 6.11.1 (emsdk 4.0.7); I have also tried on Qt6.7.3 (emsdk 3.1.50) with the same result.
-
Hi,
Why are you calling
return QCoreApplication::exec()rather thanreturn app.exec();?
While the method is static, it's from two different classes and they don't do exactly the same thing.