#include <QApplication>
#include <QFileDialog>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString filePath = QFileDialog::getOpenFileName(nullptr, "选择文件", "", "All Files (*.*)"); qDebug() << "选择的文件路径:" << filePath;
QString savePath = QFileDialog::getSaveFileName(nullptr, "保存文件", "", "Text Files (*.txt)"); qDebug() << "保存的文件路径:" << savePath; return a.exec();
}
在上面的代码中,使用QFileDialog::getOpenFileName
方法来显示选择文件对话框,并返回用户选择的文件路径。使用QFileDialog::getSaveFileName
方法来显示保存文件对话框,并返回用户选择的保存路径。