温馨提示×

qt怎么打开指定路径文件

qt
小亿
365
2023-08-10 17:44:16
栏目: 编程语言

在Qt中,可以使用QDesktopServices的openUrl函数来打开指定路径文件。以下是示例代码:

#include <QApplication>
#include <QDesktopServices>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString filePath = "C:/path/to/your/file.txt"; // 指定文件路径
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
return a.exec();
}

在上面的示例中,我们通过QDesktopServices::openUrl函数来打开指定路径的文件。QUrl::fromLocalFile函数用于将文件路径转换为本地文件URL。你只需将filePath变量设置为你要打开的文件的路径即可。

0