QT打開文件

這裏我們使用QT中的QFileDialog類。

查找幫助文檔,調用函數

QString QFileDialog::getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = Q_NULLPTR, Options options = Options())

例子:

 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                  "/home",
                                                  tr("Images (*.png *.xpm *.jpg)"));

第一個參數爲this指針,第二個爲標題欄題目,第三個爲路徑,第四個爲類型文件。

The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected. Only files that match the given filter are shown. The filter selected is set to selectedFilter. The parameters dirselectedFilter, and filter may be empty strings. If you want multiple filters, separate them with ';;', for example:


  "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

注:

 中文標題可以使用函數QString::fromLocal8Bit();


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章