Search code examples
macosqtqt4

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


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 native Mac OS X dialog.

This works:

fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop",QString(),0,QFileDialog::DontUseNativeDialog);

This doesn't work:

fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop");

It looks like if most of the time it opens the last path of the last call to getOpenFileName.


Solution

  • 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.