QT——文件对话框QFileDialog

来源:互联网 发布:淘宝主图制作教程 编辑:程序博客网 时间:2024/05/18 03:59

QStringListQFileDialog::getOpenFileNames(QWidget* parent = 0, constQString& caption = QString(), constQString& dir = QString(), constQString & filter = QString(),QString* selectedFilter = 0,Options options = 0) [static]

这是一个便利的静态类,(以“路径+文件名”的方式)返回一个或多个被用户选择的文件。

--------------------------------------------------------------------------------------------
QStringList files = QFileDialog::getOpenFileNames(
                        this,
                        "Select one or more files to open",
                        "/home",

                        "Images (*.png *.xpm *.jpg)");

该函数在跟定的 parent widget 上创建一个模式文件对话框。如果 parent 参数不为 0,对话框将被显示在 parent widget 的中间。

--------------------------------------------------------------------------------------------

该文件对话框的工作目录被设定到 dir 上。如果dir 包含文件名,则这个文件将被选择。The filter is set to filter so that only those files which match the filter are shown. The filter selected is set to selectedFilter. The parametersdir, selectedFilter and filter may be empty strings. 如果需要多重过滤,用';;'将它们分开。例如:


"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
The dialog's caption is set to caption. If caption is not specified then a default caption will be used.

--------------------------------------------------------------------------------------------

On Windows, and Mac OS X, this static function will use the native file dialog(使用本地对话框) and not a QFileDialog.

--------------------------------------------------------------------------------------------

Note: 如果想要迭代文件列表,你应该遍历的是一个副本。For example:

QStringListlist = files; //QStringList  Inherits:QList<QString>
QStringList::Iterator it = list.begin();
while(it != list.end()) {
    myProcessing(*it);
    ++it;

}

或者用下面的方式进行遍历:

for(int i=0; i<files.size(); ++i) {
        QString path=QDir::toNativeSeparators(files.at(i));
        if(!path.isEmpty()) {
            ;
        }
    }
note:QString QDir::toNativeSeparators(const QString & pathName) [static]
/* Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.*/
0 0
原创粉丝点击