QT——文件对话框QFileDialog

QStringListQFileDialog::getOpenFileNames(QWidget* parent = 0, constQString & caption = QString(), constQString& dir = QString(), const QString & 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.*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值