#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtCore>
#include <QtNetwork/QtNetwork>
#include <QDebug>
#include <QString>
#include <QIcon>
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0, QString link);
QString link;
QIcon* icon;
QByteArray* byteArr;
~MainWindow();
private:
QNetworkAccessManager *pNetManager;
public slots:
void slotReadyRead();
void slotError(QNetworkReply::NetworkError);
void slotFinished();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent, QString link)
: QMainWindow(parent)
{
pNetManager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl(link));
// request.setRawHeader("Accept-Encoding", "gzip,deflate");
QNetworkReply *reply = pNetManager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()), this, SLOT(slotFinished()));
}
void MainWindow::slotReadyRead()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
}
void MainWindow::slotFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
byteArr = reply->readAll();
icon = byteArr;
reply->deleteLater();
}
void MainWindow::slotError(QNetworkReply::NetworkError error)
{
}
MainWindow::~MainWindow()
{
}
Add a code snippet to your website: www.paste.org