I have the following client appln declaration -
{
Q_OBJECT
public:
~clientapp();
public slots:
void downloadFile();
void fileDownloaded(QNetworkReply*);
private:
Ui::clientapp ui;
QNetworkAccessManager *manager;
QNetworkReply *reply;
};
class clientapp : public QMainWindow
{
Q_OBJECT
public:
clientapp(QWidget *parent = 0);
~clientapp();
public slots:
void downloadFile();
void fileDownloaded(QNetworkReply*);
private:
Ui::clientapp ui;
QNetworkAccessManager *manager;
QNetworkReply *reply;
};
To copy to clipboard, switch view to plain text mode
The implementation of the slots are as shown -
void clientapp::downloadFile()
{
//download file
//currently hardcoded
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(fileDownloaded(QNetworkReply*)));
reply = manager->get(QNetworkRequest(
QUrl("http://10.225.208.185/ywr.mp3")));
}
void clientapp::fileDownloaded( QNetworkReply* aHttpResponse )
{
QFile temp
("E:\\httpresp.mp3");
temp.write(data);
temp.close();
}
void clientapp::downloadFile()
{
//download file
//currently hardcoded
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(fileDownloaded(QNetworkReply*)));
reply = manager->get(QNetworkRequest(
QUrl("http://10.225.208.185/ywr.mp3")));
}
void clientapp::fileDownloaded( QNetworkReply* aHttpResponse )
{
QByteArray data = aHttpResponse->readAll();
QFile temp("E:\\httpresp.mp3");
temp.open(QIODevice::WriteOnly | QIODevice::Truncate);
temp.write(data);
temp.close();
}
To copy to clipboard, switch view to plain text mode
The above code is trying to download an mp3 file from a server. The server on get sends the file, but the client application is not able to download & save the file. It has a trouble downloading any type of large file. What is the solution to this ?
Bookmarks