QFileDialog::getOpenFileName doesn't set the initial directory on Mac OS 10.8 Mountain Lion

前端 未结 2 1176
予麋鹿
予麋鹿 2021-01-04 21:47

I can not change the current directory with QFileDialog with Qt 4.8. The same code works fine on Windows and Mac OS 10.6 Snow Leopard. It also works fine if I don\'t use the

相关标签:
2条回答
  • 2021-01-04 22:00

    Got the same issue with Qt5.2.0 on Mavericks... I found a work around: append a dummy file name to the directory you want to select. However, be sure not to do this on Windows because the user will see it.

    QString dir = "/Users/myuser/Desktop";
    #if defined(__APPLE__)
    dir += "/MyFile.txt";
    #endif
    fn = QFileDialog::getOpenFileName(this, "Select File", dir);
    

    Also, for those like me that instantiate a file dialog because they need more options you can also do:

    QFileDialog fileDialog(this, "Select File");
    #if defined(__APPLE__)
    fileDialog.selectFile(dir + "/MyFile.txt");
    #else
    fileDialog.setDirectory(dir);
    #endif
    ...
    
    0 讨论(0)
  • 2021-01-04 22:04

    This is a bug in Qt that is reportedly fixed in Qt 5.0.1 and Qt 4.8.4 (though it seems that it still reproducible in 4.8.4 by people (myself included)).

    This bug has been reported in JIRA as QTBUG-20771, QTBUG-28161 and finally QTBUG-35779 (which appears to have finally fully resolved the issue in Qt 5.2.1). Here is a link to the patch in Gerrit.

    0 讨论(0)
提交回复
热议问题