如何从Qt启动外部文件
How to lauch an external file from Qt?
我想打开一个pdf文件,只需双击QListWidget的一个元素。我创建了一个批处理文件来打开Acrobat Reader(Reader.bat),但我想要一个特定的pdf文件:
void MainWindow::on_FileListWidget_itemDoubleClicked(QListWidgetItem *item)
{
QFile SelectedModel(Current_Path + "/Template/" + item->text());
QString FileName;
FileName = (Current_Path + "/Template/" + item->text());
::system("e:\reader.bat");
}
1) 我不知道从QFile或QString中可以更好地识别和选择QListWidget中的文件;2) 我不知道如何将文件添加到打开Acorbat阅读器的命令中(在显示的行中,我可以打开程序,但不能打开我的文件)。知道吗?
您可以使用Qt本机方法通过调用来实现此行为
QDesktopServices::openUrl(QUrl::fromLocalFile("someFilePath"));
请参阅QUrl::fromLocalFile()和QDesktopServices::openUrl()
(请参阅本文)
看看这个:http://qt-project.org/doc/qt-5/qdesktopservices.html#openUrl
QDesktopServices::openUrl(QUrl("file://path/to/file"));
这不仅可以用默认应用程序打开文件(如果使用file://
方案),还可以用默认浏览器打开web URL(如果使用了http://
或https://
方案),或者在使用mailto://
方案的情况下用默认电子邮件客户端打开。它也适用于steam://
、itunes://
等其他方案。
相关文章:
- C++:来自外部文件的Trivia
- OpenGL - 从外部文件绘制点
- 使用外部文件中的变量进行视觉C++
- 在 UWP 视觉工作室项目中包括外部文件夹
- 在没有外部文件的情况下在应用会话之间保存变量
- 从外部文件C++调用函数
- 将外部文件中的坐标矩阵输入到 2 个数组中
- 如何在Qt小部件应用程序中翻译外部文件中的字符串?
- 如何将外部文件中的数据保存到 2D 数组中?(C++)
- C ++ tiny-js 从外部文件执行 JavaScript 函数
- 读取外部文件并在类似xml的输入中分配变量
- C++中的结构数组和外部文件
- 访问构建树中的外部文件进行测试
- Pantheios 写入外部文件
- 如何从外部文件调用C++函数
- 如何从外部文件中读取
- 从外部文件中读取字符串行并转换为十六进制
- 如何将linux demon/服务的堆栈跟踪保存到外部文件中
- 如何将输入数组从外部文件传递到主程序中
- OpenSSL:我使用存储外部文件的RSA密钥加密和解密文件,但有时我的程序会崩溃