Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileDialog::getOpenFileName Fails to Display Dialog with Native macOS

QFileDialog::getOpenFileName Fails to Display Dialog with Native macOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 947 Views 2 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.
  • B Offline
    B Offline
    bobthebuilder
    wrote on last edited by bobthebuilder
    #1

    Hi Qt Devs! I'm developing a desktop application in C++ on macOS Sequoia 15.5 with Qt 6.9.1. When I call QFileDialog::getOpenFileName from a class that inherits from QWidget while on the main thread no dialog appears and the function immediately returns an empty string. When I call QFileDialog::getOpenFileName with the QFileDialog::DontUseNativeDialog option, however, I do indeed get a dialog and can retrieve a file name. I would like to use the native dialog, is there some reason the call is not displaying a file dialog with the native version?

    In short, this code does not display a dialog on macOS:

    QFileDialog::getOpenFileName(this, tr("Please select a file."));
    

    But this code does display a dialog on macOS:

    QFileDialog::getOpenFileName(this, tr("Please select a file."), QString(), QString(), nullptr, QFileDialog::DontUseNativeDialog);
    

    Thanks!

    Edit: The same problem occurs with QFileDialog::getSaveFileName and QFileDialog::getExistingDirectory too. Other calls like QMessageBox::information do work as expected, however.

    1 Reply Last reply
    2
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please provide a complete minimal example that shows that issue. This will allow people to test in the same conditions as you.

      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
      • N Offline
        N Offline
        Naughtius Maximus
        wrote on last edited by Naughtius Maximus
        #3

        Same issue here, when I press my browse button MacOS asks me for permission to access files on a removable volume, and when I click OK, the dialog just disappears and nothing happens. The browse dialog is not showing at all.
        I'm on M4 Pro, macOS Tahoe, QT version is 6.9.2

        void MainWindow::onLoadModel()
        {
            QString path = QFileDialog::getOpenFileName(this, tr("Load  Model"), QDir::homePath(), tr("Model Files (*.csv);;All Files (*)"));
            if (path.isEmpty()) return;
            if (worker) worker->setLoadPath(path);
        }
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          michjans
          wrote on last edited by
          #4

          Yes, I can confirm this issue as well on Qt 6.9.3 and MacOS 15.6.1
          When passing QFileDialog::DontUseNativeDialog for options parameters the dialog shows correctly, e.g.:

          QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), lastOpenDir, tr("Images (*.png *.bmp *.jpg *.tif *.gif)"), nullptr, QFileDialog::DontUseNativeDialog);
          

          Note that this is a pointer to the QMainWindow of the application.

          However I found this related bug report: QTBUG-135882

          It has been closed, but when reading through the comments, apparently the solution is to replace add_executable with qt_add_executable in the CMakeLists.txt.

          I tried this and it works for me. No need to pass the QFileDialog::DontUseNativeDialog parameter anymore and it will show the native MacOS dialog correctly.

          1 Reply Last reply
          2
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Quoting the reasons from the ticket:

            The app is missing a bundle identifier, which apparently
            affects whether the OS shows native file dialogs. Set
            MACOSX_BUNDLE_GUI_IDENTIFIER to fix this.
            The reason qt_add_executable works is because
            it automatically sets 
            MACOSX_BUNDLE_GUI_IDENTIFIER if not set.
            

            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
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved