Created
November 7, 2012 05:29
-
-
Save bradley-curran/4029716 to your computer and use it in GitHub Desktop.
A helper class to download files in Blackberry 10. For more information visit cascadeswithlove.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "NetworkHelper.h" | |
#include <QDebug> | |
#include <QUrl> | |
#include <QNetworkRequest> | |
#include <QNetworkReply> | |
NetworkHelper::NetworkHelper(QObject* parent, const QString& url) : | |
QObject(parent), | |
mNetworkAccessManager(this), | |
mDownloadedData() | |
{ | |
qDebug() << "NetworkHelper"; | |
qDebug() << url; | |
connect(&mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), | |
SLOT(fileDownloaded(QNetworkReply*))); | |
QUrl qurl(url); | |
QNetworkRequest request(qurl); | |
mNetworkAccessManager.get(request); | |
qDebug() << "request sent"; | |
} | |
NetworkHelper::~NetworkHelper() | |
{ | |
qDebug() << "Network helper deconstructor"; | |
} | |
void NetworkHelper::fileDownloaded(QNetworkReply* pReply) | |
{ | |
qDebug() << "file downloaded"; | |
mDownloadedData = pReply->readAll(); | |
qDebug() << "emitting signal"; | |
//emit a signal | |
emit downloaded(); | |
} | |
QByteArray NetworkHelper::downloadedData() const | |
{ | |
qDebug() << "retrieving downloaded data"; | |
qDebug() << QString(mDownloadedData); | |
return mDownloadedData; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef NETWORKHELPER_H_ | |
#define NETWORKHELPER_H_ | |
#include <QObject> | |
#include <QByteArray> | |
#include <QNetworkAccessManager> | |
class NetworkHelper : public QObject { | |
Q_OBJECT | |
public: | |
NetworkHelper(QObject* object, const QString& url); | |
virtual ~NetworkHelper(); | |
QByteArray downloadedData() const; | |
signals: | |
void downloaded(); | |
private slots: | |
void fileDownloaded(QNetworkReply* pReply); | |
private: | |
QNetworkAccessManager mNetworkAccessManager; | |
QByteArray mDownloadedData; | |
}; | |
#endif /* NETWORKHELPER_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment