标签:locate pre col 文件 finish path ring nload loaded
void Mystack::getFtpImg(QString ftpFilePath, QString curFileName) { QNetworkAccessManager* myNetworkManager = new QNetworkAccessManager(this); QNetworkRequest myNetworkRequest; QNetworkReply *myNetworkReply; QFile* downloadedFile = new QFile("./"+curFileName); downloadedFile->open(QIODevice::WriteOnly); QUrl url; url.setScheme("ftp"); url.setUserName(config.getSet()->value("FTP_USER_NAME").toString()); url.setPassword(config.getSet()->value("FTP_PASS_WORD").toString()); url.setHost(config.getSet()->value("FTP_HOST").toString()); url.setPort(config.getSet()->value("FTP_PORT").toInt()); url.setPath(ftpFilePath); Mymethod::record("try to download file by:"+url.toString(),PRINT_INFO); myNetworkRequest.setUrl(url); myNetworkReply = myNetworkManager->get(myNetworkRequest); QObject::connect(myNetworkReply,&QNetworkReply::readyRead,[=]{ downloadedFile->write(myNetworkReply->readAll()); }); QObject::connect(myNetworkManager,&QNetworkAccessManager::finished,[=]{ if(NULL==myNetworkReply) { Mymethod::record(getCodeLocate()+"myNetworkReply is null.",PRINT_ERR); return; } if(myNetworkReply->error() == QNetworkReply::NoError) { downloadedFile->close(); Mymethod::record("download file success:"+curFileName,PRINT_INFO); } else { Mymethod::record(getCodeLocate()+QString("download file:%1 failed,err:%2").arg(curFileName).arg(myNetworkReply->errorString()),PRINT_ERR); downloadedFile->close(); } myNetworkReply->deleteLater(); downloadedFile->deleteLater(); QObject::disconnect(myNetworkManager,0,0,0); myNetworkManager->deleteLater(); }); }
Qt使用QNetworkAccessManager获取FTP文件函数
标签:locate pre col 文件 finish path ring nload loaded
原文地址:https://www.cnblogs.com/judes/p/12859318.html