Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFileDialog returns wrong path



  • Hello,

    Could somebody help me?

    Recently, I am learning QT. I want to use QFileDialog to open some file. But I don't want to use native dialog, so I set QFileOption::DontUseNativeDialog to true. It works, and I can see QT own QFileDialog.

    But there is a problem. If I use native dialog, it will select the first item by default when I enter a folder. But QT own QFileDialog doesn't act the same. Exactly, it works wrong.
    Here is the detail.
    When I open a QFileDialog, it select nothing, and the open button is disabled.
    0_1539222112351_cf71592c-ee66-47fc-a2f7-e90605dd7ba7-image.png

    Then I select a file manully, and the open button is enabled.
    0_1539222256279_ec48c082-de59-4b70-89d0-6360f7832d23-image.png

    Then I enter another folder, but it selects nothing in the folder. What's more the open button is still enabled.
    0_1539222448322_82fad506-2410-4d91-85e8-5c93100a1ccf-image.png

    Finally, I click the open button, and I get a file returned. But its path is not correctly. Its path is /tmp/VMwareDnD/config-err-2Emdj0. But the right path should be /tmp/config-err-2Emdj0
    0_1539222965601_3bede7d3-5d68-4e57-a461-1c4f6c9a5dfa-image.png

    What should I do to solve this problem?

    My environment.
    ubuntu 16.04
    0_1539223029901_83814b4c-e91b-4b83-afff-b15394edc347-image.png
    0_1539223058094_42e92609-1280-45b2-862f-06add43df7f3-image.png

    Thanks.


  • Qt Champions 2019

    @Qingshui-Kong Did you check in Qt bug tracker whether this is a known issue? If it is not you can file a bug.



  • @jsulm
    Thanks.

    I find a similar bug https://bugreports.qt.io/browse/QTBUG-2947. It was closed. But it was not soveld completely.


  • Qt Champions 2019

    @Qingshui-Kong It isn't solved at all:
    "Resolution: Out of scope"
    "Fix Version/s: Some future release"

    I don't know why it is considered as "Out of scope".
    Nobody voted for it. Maybe you can try to reopen it or file a new one.



  • @jsulm

    Yes. It isn't solved. But something must have changed. Because in my software the open button will be disabled, if I delete the file name.

    Maybe, the reason is that it is a suggestion. But I think it is a bug!


  • Qt Champions 2019

    @Qingshui-Kong Isn't this exactly your problem:
    "1) While browsing across different directories, if you select a file and
    move to another directory, that file name does not get cleared from
    'File name' text box.".



  • @jsulm

    Yes, it is.

    You can see that from the picture I attached.



  • @Qingshui-Kong
    The bug was reported in 2008 but never addressed, it seems. You could re-open the issue.

    You cannot affect the path it returns in this situation. The one it returns is "correct" in the sense of what the final screenshot shows, but that's not really the point.

    What I suspect you really need to address is: it is possible for the dialog to return a file path which does not exist for a number of reasons, your code must handle the possibility.



  • @JonB

    Thanks! Yes, the bug was reported before but never addressed. I reported a new bug.

    I solved it by disabling the open button and clearing the lineedit in my slot for the currentChanged signal.

    But I think there are some other bugs about the DontUseNativeDialog QFileDialog.


Log in to reply