-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageload.cpp
46 lines (37 loc) · 865 Bytes
/
imageload.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "imageload.h"
imageLoad::imageLoad()
{
access=new QNetworkAccessManager(this);
//when download data is finished finished slot is called
connect(access,SIGNAL(finished(QNetworkReply*)),this,SLOT(finished(QNetworkReply*)));
}
imageLoad::~imageLoad()
{
if(access != NULL)
delete access;
}
void imageLoad::load(QString url)
{
//get data from url
access->get(QNetworkRequest(url));
}
void imageLoad::finished(QNetworkReply *reply)
{
//if no error
if(reply->error()==0)
{
//new pixmap variable
QPixmap *p=new QPixmap;
//convert QByteArray to QPixmap
p->loadFromData(reply->readAll());
qDebug("Image load succeed");
//send QPixmap
emit image(p);
}
//if error send NULL
else
{
qDebug("Image load failed");
emit image(NULL);
}
}