硬件開發(fā)軟件寧波seo推薦
簡介
● Qt中的類QProcess支持在程序中另外開辟線程
● 其中start方法支持以字符串為參數執(zhí)行命令
以Linux平臺為例:
方式一(后臺執(zhí)行)
///
/// \brief MainWindow::cmdLine run a linux command with string format in the bash
/// \param strCmd linux command in string format
///
void MainWindow::cmdLine(QString strCmd)
{QProcess process;process.start("bash",QStringList() << "-c" << strCmd);process.waitForFinished();process.close();
}
但該命令看不到執(zhí)行過程。
方式二 (終端執(zhí)行)
● 可以下述方式調用該函數,新建終端執(zhí)行腳本
QString strCmd = QString("gnome-terminal -x bash -c \"sh Run.sh run %1 %2 %3;\"").arg(this->vecPoint.size()).arg((int)(this->raleMapWidth)).arg((int)(this->raleMapHeight));
this->cmdLine(strCmd);
即運行時會彈出終端窗口,查看腳本的標準輸出。