qt 实现单击按钮打开指定文档
实现槽函数
void MainWindow::hglpFormat()
{
QString runPath = QCoreApplication::applicationDirPath(); //获取exe路劲。
QString hglpName = "hglp_file_format.pdf";
QString hglpPath = QString("%1/%2").arg(runPath).arg(hglpName);
QFile bfilePath(hglpPath);
if(!bfilePath.exists()){
return;
}
QString filePath = "file:///" + hglpPath; //打开文件夹用filse:///,打开网页用http://
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
信号与槽机制连接方式:
connect(m_hglpFormatBtn, SIGNAL(clicked()), this, SLOT(hglpFormat()));
本文介绍如何使用Qt在应用程序中实现单击按钮后打开指定的PDF文档。通过编写槽函数并利用QDesktopServices::openUrl方法结合QUrl::fromLocalFile来完成本地PDF文件的打开操作。
1587

被折叠的 条评论
为什么被折叠?



