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() hangs in Windows when using the native dialog

QFileDialog::getOpenFileName() hangs in Windows when using the native dialog

Scheduled Pinned Locked Moved General and Desktop
20 Posts 12 Posters 18.6k 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.
  • K Offline
    K Offline
    kasunf
    wrote on 14 Dec 2014, 22:03 last edited by
    #1

    Hi,

    I'm using QT 5.3.1 and I noticed that my program hangs in Windows 7 (64bit) with following arguments to the function.

    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
    "/home",
    tr("Images (*.png *.xpm *.jpg)"));

    However, if I use the option QFileDialog::DontUseNativeDialog, then it won't hang and will show the non-native file open dialog. I would prefer to use the native windows dialog so can anyone tell me if this is a bug or not?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Dec 2014, 22:44 last edited by
      #2

      Hi and welcome to devnet,

      Strange but are you aware that you are trying to open a probably non existent folder ? There's no /home on windows. However you can use QDir::home() to get the current user home path

      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
      • K Offline
        K Offline
        kasunf
        wrote on 14 Dec 2014, 22:57 last edited by
        #3

        Yes, this is just an example syntax for this post.
        My syntax is as follows:

        fileName = QFileDialog::getOpenFileName(this,
        tr("Select file"),
        QString(),
        tr("Files (*.cvs *.svf *.txt)"));

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Dec 2014, 23:13 last edited by
          #4

          Do you have any network drive ?

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

          W 1 Reply Last reply 5 Nov 2015, 10:33
          0
          • K Offline
            K Offline
            kasunf
            wrote on 14 Dec 2014, 23:17 last edited by
            #5

            No I don't. I just have a C:\ drive and couple of removable drives, which are not active.
            This problem was reproduced on another PC other than mine.

            [quote author="SGaist" date="1418598787"]Do you have any network drive ?[/quote]

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Dec 2014, 21:29 last edited by
              #6

              Which version of Windows ?

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

              H 1 Reply Last reply 17 May 2015, 22:19
              0
              • K Offline
                K Offline
                kasunf
                wrote on 15 Dec 2014, 21:45 last edited by
                #7

                It is Windows 7 Professional (64bit).

                Looking at the history of Qt, I think this possibly has been a bug for some time (possibly since QT4)....
                I have seen at least 1 reported case of this sort of behaviour....

                [quote author="SGaist" date="1418678949"]Which version of Windows ?[/quote]

                1 Reply Last reply
                0
                • S SGaist
                  15 Dec 2014, 21:29

                  Which version of Windows ?

                  H Offline
                  H Offline
                  htettey
                  wrote on 17 May 2015, 22:19 last edited by htettey
                  #8

                  @SGaist

                  I have just recently migrated a project I am working on to Qt5.4.1 from Qt4.8.5, and I am having the same problem as reported by kasunf.

                  A call to getOpenFileName hangs - using QFileDialog::DontUseNativeDialog gets it working, but I'll prefer to use te native windows dialog. The code snippet is shown below:

                  m_imageFile = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)"), 0, QFileDialog::DontUseNativeDialog); //works

                  m_imageFile = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)")); //does not work

                  Program control does not seem to return from this function call. Has this issue been resolved? My system specifications are as follows:

                  Windows7 64bit
                  Visual Studio 2010
                  Qt5.4.1_opengl

                  PS: I did not have this problem with Qt4.8.5

                  Thanks,

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 19 May 2015, 21:44 last edited by
                    #9

                    Do you mean that when you click OK the dialog disappear but your application doesn't do anything ?

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

                    H 1 Reply Last reply 20 May 2015, 06:38
                    0
                    • S SGaist
                      19 May 2015, 21:44

                      Do you mean that when you click OK the dialog disappear but your application doesn't do anything ?

                      H Offline
                      H Offline
                      htettey
                      wrote on 20 May 2015, 06:38 last edited by
                      #10

                      @SGaist Nope, that is not what I mean.

                      The open fIle dialog does not appear at all - as though my application is waiting for it to appear. After investigations it turns out that it seems to hang in the call to

                      QFileDialog::getOpenFileName(...)

                      As I indicated, a call to QFileDialog::getOpenFileName(...) using the flag QFileDialog::DontUseNativeDialog returns from the function call, but the same function call without using the flag does not return.

                      I will like to use it without the flag. Also, I didn't have this problem in Qt4.8.5.

                      Please this is the same problem as first reported on this post. I just need to know what the status of this issue is.

                      PS: I am interested in purchasing a commercial license for Qt5, but I need to make sure that my project works in Qt5 before going ahead with the purchase.

                      Thanks,

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 28 May 2015, 21:20 last edited by
                        #11

                        Which compiler are you using ? Just tested with VS2013 on Win 8 and no problem with the dialog.

                        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
                        • G Offline
                          G Offline
                          GirishJ
                          wrote on 18 Aug 2015, 11:02 last edited by GirishJ
                          #12

                          Facing exactly same problem on Windows 7 pro (64-bit) with Qt5.5 MSVS2010 Professional with Qt Add-in.

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 18 Aug 2015, 12:02 last edited by
                            #13

                            win 7. 64 bit, Qt 5.5, "gcc"
                            No hanging at all.
                            So maybe only VS?

                            Please Try with QFileDialog::DontUseCustomDirectoryIcons
                            As i had case where it would take ages due to subversion overlay icons.

                            1 Reply Last reply
                            1
                            • R Offline
                              R Offline
                              Rondog
                              wrote on 18 Aug 2015, 12:43 last edited by
                              #14

                              I have used most of the Qt versions mentioned in this thread and never had a problem with using the getOpenFileName(...) member function with native dialogs. I have always used MinGW for Windows so maybe this problem is unique to Visual Studio?

                              1 Reply Last reply
                              0
                              • S SGaist
                                14 Dec 2014, 23:13

                                Do you have any network drive ?

                                W Offline
                                W Offline
                                Wesley
                                wrote on 5 Nov 2015, 10:33 last edited by
                                #15

                                @SGaist said:

                                Do you have any network drive ?

                                I have a problem using the functions QFileDialog::getSaveFileName and QFileDialog::getOpenFileName on a PC with many network drives. Could you please help on this? Thanks.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dan-42
                                  wrote on 26 Apr 2019, 09:03 last edited by dan-42
                                  #16

                                  Just to note this issue still exists, but does not happen on all QFileDialogs instances used in our software.

                                  When does it work:

                                  On the very first start-screen, when no other backend-threads are running, no COM connection is created etc.

                                  When does it not work

                                  Some where later in the application, when backend-threads are running, COM connection to a different application is established.

                                  Setup:

                                  Qt 5.12.3
                                  MSVC 2017 v15.9.7
                                  Windows 10 build1809

                                  The issue is reproducible on different computers in Debug and Release Build

                                  Observations

                                  Opening The QFileDialog leads to the following:

                                  The Main-UI is blocked and you can hear the windows-sound that comes, when the UI is blocked because a Dialog is in front and the user clicks somewhere on the Main-UI.

                                  Then

                                  Switching between applications (Alt-Tab) then hitting ESC, and the Main-UI is responsible again.
                                  This indicates, that there is an invisible Dialog on top of the main-UI.

                                  Opening The QFileDialog again

                                  Then it works!

                                  1 Reply Last reply
                                  6
                                  • Gwen5484G Offline
                                    Gwen5484G Offline
                                    Gwen5484
                                    wrote on 29 Aug 2019, 16:05 last edited by
                                    #17

                                    Same symptoms here, with QFileDialog::getExistingDirectory.

                                    • Before loading the COM objets, the dialog opens well, with native window.
                                    • After laoding COM (CoInitializeEx), calling getExistingDirectory causes the program to hang.
                                    • After disconnecting COM (CoUninitialize), the dialog opens well again, but with Qt window (not native) even though I did'nt specify the DontUseNativeDialog option!

                                    Qt 5.12.1, MSVC 2017, Windows 10

                                    1 Reply Last reply
                                    1
                                    • JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on 29 Aug 2019, 16:57 last edited by
                                      #18

                                      Clearly nasty COM behaviour. I am not a Qt expert, but since your post and the previous one are nice and clear on the reproducibility, the best would be to (search first and then) report them at https://bugreports.qt.io/secure/Dashboard.jspa, see also https://wiki.qt.io/Reporting_Bugs.

                                      1 Reply Last reply
                                      1
                                      • V Offline
                                        V Offline
                                        Vortex0911
                                        wrote on 7 Jun 2024, 17:49 last edited by
                                        #19

                                        Yeah I am encountering the same problem in 2024. This condition is also caused by QSplitter for some reason. Setting my "central" widget to QSplitter just causes it to permanently block a thread for some reason. But somehow setting the don't use native dialog option allows me to open it. If you have some suggestion for me do tell as I am a complete noob

                                        1 Reply Last reply
                                        0
                                        • RichardR Offline
                                          RichardR Offline
                                          Richard
                                          wrote on 18 Jun 2024, 08:15 last edited by Richard
                                          #20

                                          We encountered this problem years ago. And this was caused by programs from DELL, "Dell Backup and Recovery", "Dell Optimizer", "Dell Power Management". These programs use Qt too, even statically compiled, but in a nasty way that prevented using newer Qt versions. And it crashed our software when you open a file dialog using native dialog on windows. Problems were solved once these programs were uninstalled.

                                          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