Bug 406464

Summary: Unexpected folder selection in native QFileDialog
Product: [Plasma] plasma-integration Reporter: Michael Weghorn <m.weghorn>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED WORKSFORME    
Severity: normal CC: kde, m.weghorn, nate
Priority: NOR    
Version: 5.14.5   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Sample program that opens QFileDialog to select directory
screenshot with native Plasma file dialog
screenshot of non-native QFileDialog

Description Michael Weghorn 2019-04-12 11:05:48 UTC
Created attachment 119370 [details]
Sample program that opens QFileDialog to select directory

SUMMARY

When using the native Plasma file dialog to select a directory, clicking on a directory and confirming will not select the selected directory, but the "base directory" currently shown in the dialog.


STEPS TO REPRODUCE
1. create test directories: 'mkdir /tmp/testdir/subdir'
2. compile attached sample program ("main.cpp") that opens a file dialog to select a directory
3. start the program
4. navigate into directory "/tmp/testdir"
5. click on directory "subdir"
6. click the "Open" button
  -> dialog closes
7. check what directory has been selected (printed on stdout for the sample program) 

OBSERVED RESULT

The folder "/tmp/testdir/" has been selected.


EXPECTED RESULT

Expected result: The folder "/tmp/testdir/subdir" should be selected.


SOFTWARE/OS VERSIONS
Debian 

Operating System: Debian GNU/Linux testing (with plasma-integration 5.14.5-1, libkf5kiowidgets5 5.54.1-1)
KDE Plasma Version: 5.14.5
Qt Version: 5.11.3
KDE Frameworks Version: 5.54.0
Kernel Version: 4.19.0-4-amd64
OS Type: 64-bit


ADDITIONAL INFORMATION

* The non-native QFileDialog behaves as expected, which can be tested by forcing QFileDialog to use non-native mode (s. line 11, currently commented out). When clicking a directory, it updates that shown path accordingly and the test program prints the path after clicking the "Choose" button.
* The attached screenshots show the native and non-native dialogs at the point in time the corresponding buttons are clicked.
* The Qt documentation for QFileDialog ([1]) mentions: "Returns a list of strings containing the absolute paths of the selected files in the dialog. If no files are selected, or the mode is not ExistingFiles or ExistingFile, selectedFiles() contains the current path in the viewport." -- I don't thinks this describes what happens here, though.
* Commenting out 'dialog.setFileMode(QFileDialog::FileMode::Directory);' in line 12 in the sample program makes the QFileDialog behave as expected. However, that will make folder selection impossible with the non-native QFileDialog (so behaviour differs here as well).

[1] https://doc.qt.io/qt-5/qfiledialog.html#selectedFiles
Comment 1 Michael Weghorn 2019-04-12 11:06:20 UTC
Created attachment 119371 [details]
screenshot with native Plasma file dialog
Comment 2 Michael Weghorn 2019-04-12 11:06:53 UTC
Created attachment 119372 [details]
screenshot of non-native QFileDialog
Comment 3 Michael Weghorn 2021-09-03 11:35:22 UTC
This works as expected now after upgrading from Debian bullseye to bookworm (current testing) which also has newer versions of the Plasma/kf5 packages, e.g.

* plasma-integration/testing,now 5.21.5-2
* libkf5kiocore5/testing,now 5.83.0-2

-> closing as WORKSFORME

(This may or may not be related to the fix for bug 419874, I didn't take a closer look.)