Details
Description
When using QNetworkAccessManager to download a file from HTTP everything works.
But when using it for downloading a file from FTP, you cannot abort the download completely.
In this case all signals from QNetworkReply will be emit correctly, but in the background it is still downloading.
Abort.h
#ifndef ABORT_H_ #define ABORT_H_ #include <QDebug> #include <QNetworkReply> #include <QObject> class Abort : public QObject { Q_OBJECT private: QNetworkReply *_reply; public: Abort( QNetworkReply *reply ) : _reply( reply ) {} virtual ~Abort() {} public slots: void abort() { if ( _reply ) { qDebug() << "Calling abort!"; _reply->abort(); } } }; #endif /* ABORT_H_ */
TestFtpAbort.cpp
#include <QNetworkAccessManager> #include <QTimer> #include <QEventLoop> #include <QUrl> #include <QCoreApplication> #include "Abort.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QNetworkAccessManager man; QString file = "ftp://ftp.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.8.1.zip"; // QString file = "http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.8.1.zip"; QNetworkReply *reply = man.get( QNetworkRequest( QUrl( file ) ) ); Abort abort( reply ); QTimer::singleShot( 5000, &abort, SLOT( abort() ) ); return app.exec(); }