Qt提供了QDesktopServices类, 可以利用openUrl函数调用默认程序打开文件;
源码参考:
#ifdef Q_OS_WIN32
m_szHelpDoc = QString("file:///") + m_szHelpDoc;
bool is_open = QDesktopServices::openUrl(QUrl(m_szHelpDoc, QUrl::TolerantMode));
if(!is_open)
{
LogWriter::getLogCenter()->PrintLog(LOG_ERROR,"open help doc failed" );
LogWriter::getLogCenter()->SaveFileLog(LOG_ERROR,"open help doc failed" );
return;
}
#else
QString cmd= QString("xdg-open ")+ m_szHelpDoc; //在linux下,可以通过system来xdg-open命令调用默认程序打开文件;
system(cmd.toStdString().c_str());
#endif