qscopedpointerm_process;
m_process.reset(new qprocess(this));
connect(m_process.data(), signal(readyreadstandardoutput()), this, slot(onreadyread()));
connect(m_process.data(), signal(finished()), this, slot(onfinished()));
m_process->setreadchannel(qprocess::standardoutput);
m_process->start("***.exe");
m_process->waitforfinished(-1);
qstring output = m_process->readallstandardoutput();
void mythread::onreadyread()
}void mythread::onfinished()
第一種方式的思路是在onreadyread訊息中一行一行讀取輸出資訊,然後在程序結束後用readallstandardoutput把剩餘的資料讀取出來。qscopedpointerm_process;
m_process.reset(new qprocess(this));
connect(m_process.data(), signal(readyreadstandardoutput()), this, slot(onreadyread()));
connect(m_process.data(), signal(finished()), this, slot(onfinished()));
m_process->setreadchannel(qprocess::standardoutput);
m_process->start("***.exe");
m_process->waitforfinished(-1);
void mythread::onreadyread()
void mythread::onfinished()
但是反覆執行程式會崩潰退出,報錯資訊如下
assert: "bytes <= buffersize" in file tools\qringbuffer.cpp, line 74
經測試發現如果finish訊息先收到,後執行readallstandardoutput會報錯。如果不加readallstandardoutput,程序輸出不會完整讀取。嘗試用了變數,互斥鎖,訊號量都沒法解決,因為finish訊息的到來是隨機的。
如果把readallstandardoutput放在finish訊息裡面有時也會崩潰。並且看不到崩潰資訊。
最後發現在waitforfinished後面加乙個100毫秒延遲就好了,qthread::msleep(100)。
第二種方法的思路是在onreadyread訊息中直接讀取所有輸出資料,經測試,可以完整讀出資料並且不會崩潰。
QProcess怎麼實時的讀到output的資訊
在qt裡想與子程式通訊,一般都會用到qprocess這個類,而且手冊裡也提到了很多通訊的方法,比如手冊裡的 communicating via channels 我也不例外,用的也是這貨,但在實際操作中,還是遇到不少問題.我的目的是 在主程式裡呼叫 lftp.exe 來將一些檔案上傳到伺服器上.貌似...
QProcess呼叫外部程式死迴圈標準輸出實時重新整理
c語言程式應禁止緩衝,如果寫的arm程式準備用於這種途徑,且需要實時被讀取標準輸出,那麼一般該程式內需要禁用緩衝 int main 因為在控制台執行時,標準輸出是行緩的。但是使用管道或重定向以後,一般就是全緩衝。在緩衝區寫滿或程式退出前,你可能看不到任何輸出。在qt程式端,應該將connect 函式...
(一)js jquery實時監聽輸
1 先說jquery,使用jquery庫的話,只需要同時繫結 oninput 和 onpropertychange兩個事件就可以了,示例 username bind inputpropertychange function 2 對於js原生寫法而言,oninput 是html5的標準事件,對於檢測 ...