#include <QtGui/QApplication>
#include <QtCore/QTextCodec>
#include <QFileDialog>
#include <QString>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QString path = QFileDialog::getOpenFileName(NULL, QObject::tr("打开"), ".", QObject::tr("文件类型(*.jpg *.png)"));
QString path = QFileDialog::getSaveFileName(NULL, QObject::tr("保存"), ".", QObject::tr("文件类型(*.jpg *.png)"));
return app.exec();
}
提供的是Windows和Linux平台上的本地对话框
#include <QtGui/QApplication>
#include <QtCore/QTextCodec>
#include <QFileDialog>
#include <QString>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QFileDialog fileDialog;
fileDialog.setWindowTitle(QObject::tr("打开"));
fileDialog.setDirectory(".");
fileDialog.setFilter(QObject::tr("文件类型(*.exe *.chm)"));
fileDialog.open();
QString path = fileDialog.selectedFiles()[0];
return app.exec();
}
提供的始终是Qt自己绘制的对话框