[Qt-interest] QFileDialog on Windows
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Wed Jun 30 17:19:16 CEST 2010
Duane Hebert wrote on Wednesday, June 30, 2010 4:47 PM:
> Using Qt 4.5.1 commercial.
> According to the docs, QFileDialog uses the native file dialog on
> Windows unless you subclass it with a class using the QObject Macro.
>
> But it seems that this is only true if you use one of the static
> functions like getOpenFilename(). In my case, when I use even
> QFileDialog directly, on the left (sidebar) I get a selection for
> only MyComputer and my home directory (documents and
> settings/myusername/blah blah)
Here is a small example which confirms that instantiating a QFileDialog you get the Qt flavour (non-native). The 2nd part which calls the static method then shows the proper native dialog. At least this is with Qt 4.6.1 on Win XP SP 3.
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFileDialog fd;
QString initialDirectory = "c:/temp/";
QString filePath;
fd.setDirectory(initialDirectory);
if (fd.exec()) {
filePath = fd.selectedFiles().at(0);
qDebug("Selected filepath (instance): %s", qPrintable(filePath));
}
filePath = QFileDialog::getOpenFileName(0, "Open", initialDirectory);
if (!filePath.isNull()) {
qDebug("Selected filepath (static): %s", qPrintable(filePath));
}
return 0;
}
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list