Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21372

QFileDialog::getExistingDirectory() incorrectly allows to select multiple directories

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.5
    • 4.7.3, 4.7.4, Some future release
    • None
    • Windows Vista and higher
    • 08d6390b2131b8c5f2b582e4dc037f1c919d5e31

    Description

      Steps to reproduce

      1. In your program, call QFileDialog::getExistingDirectory() with any valid parameters. Alternatively, you can use e.g. Qt Creator: Press Ctrl+N, choose any project and press the "Browse..." button.
      2. When the dialog is shown, select multiple directories.
      3. Press the "Select Folder" button

      Expected result

      Selecting more than one directory should not be allowed. (See http://doc.qt.nokia.com/latest/qfiledialog.html#getExistingDirectory)

      Real result

      It is possible to select multiple directories. Moreover, if you do this a blank path is returned (the same as if the user pressed Cancel).

      Additional information

      This only happens on Windows Vista and higher. (The dialog used here is different from older Windows Versions.)
      It also happens with the latest Qt version from gitourious (git clone git://gitorious.org/qt/qt.git).

      The problem is that qt_win_CID_get_existing_directory() (src/gui/dialogs/qfiledialog_win.cpp:585) calls qt_win_set_IFileDialogOptions() with QFileDialog::ExistingFiles() (note the plural)(line 600). This could trivially be fixed by just changing it to QFileDialog::ExistingFile(). I have already tested it, and it seems to work now.

      Here is the output of git diff after applying the fix:

      $ git diff
      
      diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp
      index 78803ba..1924c58 100644
      --- a/src/gui/dialogs/qfiledialog_win.cpp
      +++ b/src/gui/dialogs/qfiledialog_win.cpp
      @@ -597,7 +597,7 @@ QString qt_win_CID_get_existing_directory(const QFileDialogArgs &args)
           if (SUCCEEDED(hr)) {
               qt_win_set_IFileDialogOptions(pfd, args.selection,
                                             args.directory, args.caption,
      -                                      QStringList(), QFileDialog::ExistingFiles,
      +                                      QStringList(), QFileDialog::ExistingFile,
                                             args.options);
      
               // Set the FOS_PICKFOLDERS flag
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            andysh Andy Shaw
            cn Christian N.
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes