1、打开目录
void MainWindow::on_openDirectory_btn_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, "打开目录", "D:/");
QMessageBox::information(this, "打开目录", "您选择的目录是:" + dir);
}
2、打开文件(单)
void MainWindow::on_openFile_btn_clicked()
{
QString arg("Text files(*.txt)");
QString dir = QFileDialog::getOpenFileName(this, "打开文件", "D:/", "Images(*.png *.jpg);;Text files(*.txt)", &arg);
QMessageBox::information(this, "打开文件", "您选择的文件是:" + dir);
}
3、打开文件(多)
void MainWindow::on_openFiles_btn_clicked()
{
QStringList dirs = QFileDialog::getOpenFileNames(this, tr("Open Files"), "D:/", tr("Images(*.png *.jpg);;Text files(*.txt)"));
QString names;
for(int i=0; i<dirs.size(); i++)
{
names += dirs.at(i) + " ";
}
QMessageBox::information(this, "打开文件", "您选择的路径为:" + names);
}
4、保存文件
void MainWindow::on_saveFile_btn_clicked()
{
QString dir = QFileDialog::getSaveFileName(this, tr("保存文件"), tr("D:/"));
QMessageBox::information(this, "保存文件", "您指定的保存数据的文件是:" + dir);
}