织梦CMS - 轻松建站从此开始!

罗索

Qt 打开文件对话框

jackyhwei 发布于 2011-03-20 18:12 点击:次 
Qt 打开文件对话框实现代码(打开单个文件,打开多个文件)
TAG:

1.打开单个文件

QString filename = QFileDialog::getOpenFileName(
   this,
   "Open Document",
   QDir::currentPath(),
   "Document files (*.doc *.rtf);;All files(*.*)");
if (!filename.isNull()) { //用户选择了文件
   // 处理文件
   QMessageBox::information(this, "Document", "Has document", QMessageBox::Ok | QMessageBox::Cancel);
} else // 用户取消选择
   QMessageBox::information(this, "Document", "No document", QMessageBox::Ok | QMessageBox::Cancel);

2. 可以选定多个文件的文件打开对话框

    QFileDialog::Options options;
    if (!native->isChecked())
        options |= QFileDialog::DontUseNativeDialog;
    QString selectedFilter;
    QStringList files = QFileDialog::getOpenFileNames(
                                this, tr("QFileDialog::getOpenFileNames()"),
                                openFilesPath,
                                tr("All Files (*);;Text Files (*.txt)"),
                                &selectedFilter,
                                options);
    if (files.count()) {
        openFilesPath = files[0];
        openFileNamesLabel->setText(QString("[%1]").arg(files.join(", ")));
    }

(cybertingred)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201103/11099.html]
本文出处:百度博客 作者:cybertingred
顶一下
(2)
40%
踩一下
(3)
60%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容