PDA

View Full Version : Problem in mp3 file receive by client application



ada10
17th August 2010, 12:53
I have the following client appln declaration -



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;
};


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 )
{

QByteArray data = aHttpResponse->readAll();
QFile temp("E:\\httpresp.mp3");
temp.open(QIODevice::WriteOnly | QIODevice::Truncate);
temp.write(data);
temp.close();


}

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 ?

squidge
17th August 2010, 17:43
Perhaps it is not client issue, but server issue, did you confirm that the server sends all the bytes?

ada10
18th August 2010, 04:47
I have seen that the server sends all the bytes. The problem is at the client end itself. Any solutions for this ?

squidge
18th August 2010, 07:49
Yes, instead of trying to grab all the bytes at once, use readyRead signal and grab the bytes as they come in. Maybe it solves your problem.

ada10
18th August 2010, 08:13
Yes,using the readyRead() signal helped me to get the mp3 files. Works well with large sized files also. Thanks a lot.