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. [SOLVED] QFileDialog.setFileMode() gives wrong behaviour under Windows
QtWS25 Last Chance

[SOLVED] QFileDialog.setFileMode() gives wrong behaviour under Windows

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.7k 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.
  • Q Offline
    Q Offline
    qt-pr
    wrote on last edited by
    #1

    I am creating an instance of QFileDialog (Qt5.0.2.) which I want to use to allow the user to select a directory. After creation but before showing the dialog, I am executing the setFileMode(QFileDialog::Directory) method to specify the desired behaviour. Under Linux this does exactly what I think it should. So far, so good.

    When I cross-build (the same project) for Windows under Linux (using the MXE cross tools), the QFileDialog reverts to its default behaviour of only allowing the user to select a file. If the user selects a directory, that directory is opened, not selected. This happens under both Wine and on running the cross-built executable on WinXP.

    Further, if I build the project natively on WinXP, I still get the wrong behaviour in QFileDialog.

    I have added an assert after executing setFileMode() to check the file mode using the fileMode() method and it appears correct. The title of the QFileDialog instance is "Find Directory" (which I am not setting separately).

    Am I missing something obvious or is this a pretty egregious bug?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      Try with
      @ fD->setFileMode(QFileDialog::Directory);
      fd->setOption(QFileDialog::ShowDirsOnly, true);
      @

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qt-pr
        wrote on last edited by
        #3

        [quote author="b1gsnak3" date="1366704212"]Try with
        @ fD->setFileMode(QFileDialog::Directory);
        fd->setOption(QFileDialog::ShowDirsOnly, true);
        @[/quote]

        This doesn't work properly either! Setting the file dialog to show only directories, I still can see files! And the file type combo box at the bottom still says "Any file (.)". (Works absolutely as documented under Linux though.) So this is the second instance of incorrect behaviour under Windows.

        I am beginning to suspect this is a depressingly elementary bug ...in a piece of s/w in its 5th major version. Can anybody else reproduce this problem to confirm its either a bug or there is something awry in what I am doing?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          Maybe add

          @fD->setOption(QFileDialog::DontUseNativeDialog, true);@

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            and what when you use the "static method":http://qt-project.org/doc/qt-4.8/qfiledialog.html#getExistingDirectory? Does the problem persist?
            Or do you depend on the non-OS-native file dialog?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qt-pr
              wrote on last edited by
              #6

              [quote author="b1gsnak3" date="1366710804"]Maybe add

              @fD->setOption(QFileDialog::DontUseNativeDialog, true);@[/quote]

              This cracks the problem! Thanks!

              (How do I mark this thread as solved?)

              1 Reply Last reply
              0
              • B Offline
                B Offline
                b1gsnak3
                wrote on last edited by
                #7

                Your welcome. Edit your first post and at the title add [SOLVED]

                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