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()));