QT 防止FTP 上传软件在断连处 Crash
生活随笔
收集整理的這篇文章主要介紹了
QT 防止FTP 上传软件在断连处 Crash
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前段時(shí)間發(fā)現(xiàn)項(xiàng)目中的上傳FTP軟件有可能會(huì)在從服務(wù)器申請斷連時(shí)Crash, 所以加了一個(gè)Timer。
由于項(xiàng)目代碼行數(shù)過大, 此處上傳部分代碼片段。
timeoutTimer = new QTimer();connect(timeoutTimer, SIGNAL(timeout()), this, SLOT(doTimeout()));timeoutTimer->setInterval(4000); case QFtp::Closing:// The connection is closing down, but it is not yet closed. (The state will be Unconnected when the connection is closed.)pMain->debug( "Status(%d) = disconnecting from HOST", type );timeoutTimer->start();break; case QFtp::Unconnected:// There is no connection to the host.pMain->debug( "Status(%d) = disconnected status", type );if ( communicator->isPerforming() ) {communicator->abortRequest(); // abort performing command, maybe done(ERROR) should be called later }timeoutTimer->stop(); //stop timerbreak; /** *@projectName BoeB9Project *@author Hasan **/ void FtpHelper::doTimeout() {pMain->debug("debug154545 timeout !!!!!!!");pMain->sendProxyMessage("MesUPLOADTimeout", ProxyMessage::Notify);timeoutTimer->stop(); }在此進(jìn)程發(fā)出MesUPLOADTimeout 信息之后, 項(xiàng)目主進(jìn)程會(huì)從代理Proxy中接受此信息并進(jìn)行處理。
/***@projectName BoeB9Project*@author Hasan**/ void BoeB9QtmCellInlineMain::restartUploader() {QProcess proc;QString c = "taskkill /im uploader.exe /f";proc.execute(c);proc.close();info("********info terminate uploader");QProcess *proc1 = new QProcess(this);proc1->start("cmd.exe", QStringList() <<"/c" << "c:///ORBKwsmcu/bin/start_uploader.bat");delete proc1;info("********info start uploader again"); }主進(jìn)程重啟上傳軟件,從而跳過斷連。
轉(zhuǎn)載于:https://www.cnblogs.com/hasan/p/9161750.html
總結(jié)
以上是生活随笔為你收集整理的QT 防止FTP 上传软件在断连处 Crash的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单源最短路——dijkstra算法
- 下一篇: 如何前后端分离?