我目前正面臨一個關於QFtp的奇怪問題。我想從FTP服務器上下載一堆文件,但是當我下載到y文件後,執行了ftp->get()
命令後,文件被填充,但沒有發出SIGNAL
commandFinished()
,因此它不會下載其他文件。QFtp獲取從不發射commandFinished()
這裏是我的代碼:
void Ftp::commandFinished(int i, bool error)
{
if(ftp->currentCommand() == QFtp::Get)
{
if(error)
{
//blablabla-ERROR-blablabla
}
currentFile->close();
filesToDownload.pop_front();
processFileList();
}
/**Gestion de la commande Login (authentification de l'utilisateur)
*/
if(ftp->currentCommand() == QFtp::Login)
{//not utile here}
/**Gestion de la commande ConnectToHost (connexion au serveur)
*/
if (ftp->currentCommand() == QFtp::ConnectToHost)
{//not utile here}
/**Gestion de la commande List (téléchargement d'un fichier)
*/
if(ftp->currentCommand() == QFtp::List)
{
if(error)
{
//Nananana-FAIL-nanana
}
//!Tri des fichiers à télécharger en fonction de leur dernière date de modification
if (!filesToDownload.isEmpty())
{
currentPeripheral->setLastDownloadDate(newLastModifiedDate) ;
std::sort(filesToDownload.begin(),filesToDownload.end(),compareQUrlInfos);
processFileList();
}
}
}
void Ftp::processFileList()
{
QUrlInfo info;
if (filesToDownload.isEmpty())
{
//!Suicide de l'instance de Ftp
ftp->close();
disconnect(this,0,0,0);
this->deleteLater();
return ;
}
info = filesToDownload.first();
QDir dlDir(QString::number(currentPeripheral->getId()));
//!Si un fichier a été téléchargé, on déclenche son traitement
if (currentFile != nullptr)
{
emit(oneDownloadFinished(currentFile->fileName(),currentPeripheral));
delete currentFile;
currentFile = nullptr;
}
//!On crée un répertoire de téléchargement si nécessaire
if (!dlDir.exists())
{
dlDir.mkdir(".");
}
//!on crée le fichier qui contiendra le téléchargement
currentFile = new QFile(dlDir.filePath(info.name()));
if(!currentFile->open(QIODevice::WriteOnly))
{
delete currentFile;
currentFile = nullptr;
emit(writeToMonitoringConsole(QString("Erreur lors de la creation du fichier "+info.name()),"Error"));
return;
}
//Here I start (sometimes) a never ending fail
ftp->get(info.name(), currentFile);
}
起初我還以爲是因爲我做了太多的要求,而我被拒絕,因爲這一點,但即使有Sleep(2000)
它塊。封鎖出現得更快。我通常可以下載大約30個文件(當幸運70時,一旦我設法有200個!)。用Sleep(2000)
我幾乎沒有成功下載2-3個文件。
這是我的錯嗎? QFtp有沒有限制我沒有找到?或者是其他東西 ?
編輯:我測試了薩姆的事情,因爲我張貼,什麼是驚人的,監測dataTransferProgress()信號時,其是有問題的文件被完全下載(qDebug說:「88928分之88928」),但我從來沒有輸入commandFinished()。
我插槽commandFinished()鏈接到我的QFtp :: commandFinished信號是這樣的:
connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(commandFinished(int,bool)));
我沒有看到你的代碼中的任何commandFinished信號檢查?你能分享更多的代碼嗎? – lpapp
當一個命令完成時,commandFinished()由QFtp發出,我通常不應該自己發送這個信號。 [Qt commmandFinished](http://qt-project.org/doc/qt-4.8/qftp.html#commandFinished) – Karalix
這可能是https://bugreports.qt.io/browse/QTBUG-19409 – x29a