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. QFileDialog::getOpenFileContent opens no window
Qt 6.11 is out! See what's new in the release blog

QFileDialog::getOpenFileContent opens no window

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 176 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.
  • F Offline
    F Offline
    FX David
    wrote last edited by
    #1

    As per documentation, I was trying to allow users to select a file with QFileDialog::getOpenFileContent from 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 nameFilter to "*") 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();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Why are you calling return QCoreApplication::exec() rather than return app.exec(); ?
      While the method is static, it's from two different classes and they don't do exactly the same thing.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FX David
        wrote last edited by
        #3

        What you say is true, it's an oversight.
        That does not solve the issue I am having though: the dialog opens when compiled to desktop, not when compiled to WASM.

        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