本文介紹了讀取 QProcess 輸出到字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有一個像這樣使用 QProcess 的代碼.
I have a code that uses QProcess like this.
int main(int argc, char *argv[])
{
int status=0;
QProcess pingProcess;
QString ba;
QString exec = "snmpget";
QStringList params;
params << "-v" << "2c" << "-c" << "public" << "10.18.32.52" << ".1.3.6.1.4.1.30966.1.2.1.1.1.5.10";
status=pingProcess.execute(exec, params);
pingProcess.close();
}
這將輸出以下內(nèi)容.
SNMPv2-SMI::enterprises.30966.1.2.1.1.1.5.10 = STRING: "0.1"
我想將此輸出作為字符串讀取(讀取).我搜索了這個,但找不到解決方案.提前致謝.
I want to take(read) this output as string. I searched for this and I cant find the solution. Thanks in advance.
推薦答案
Did you try QByteArray QProcess::readAllStandardOutput()
docs - 這里
Did you try QByteArray QProcess::readAllStandardOutput()
docs - here
QString
可以從 QByteArray
實例化:
QString output(pingProcess.readAllStandardOutput());
正如其他人提到的,我也加入他們,你不應(yīng)該使用 execute
方法并將其替換為:
As others mentioned, and I join to them, you should not use execute
method and replace it with:
pingProcess.start(exec, params);
pingProcess.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
QString output(pingProcess.readAllStandardOutput());
這篇關(guān)于讀取 QProcess 輸出到字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!