#include <QHttp>
#include <QHttpRequestHeader>
#include <QHttpResponseHeader>
#include <QByteArray>
#include <QLabel>
#include <QImage>
#include <QString>
#include <QTextBrowser>
#include <iostream>
#include "image.h"
using namespace std;
Image::Image(){
dataReceived->clear();
http
= new QHttp("localhost",
80,
this);
header.setValue("Host", "localhost");
http->setHost("localhost");
http->request(header);
connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(requestFinished(int, bool)));
//connect(http, SIGNAL(done(bool)), this, SLOT(done(bool)));
setFixedSize(300, 150);
setCentralWidget(label);
show();
}
//QByteArray imageData(http->readAll());
//QImage image(imageData.data());
//QImage image("logo.png");
//label->setPixmap(QPixmap::fromImage(image));
cout << "The response:\n";
dataReceived->append(http->readAll());
cout << "dataReceived lenght: " << dataReceived->size() << endl;
//QString temp1 = dataReceived->data();
//cout << temp1.toStdString();
}
void Image::requestFinished(int n, bool error){
if(error){
cout << "requestFinished error\n";
}
else{
if(dataReceived->size()==0){
return;
}
cout << "requestFinished ok\n";
cout << "Image lenght: " << dataReceived->size() << endl;
site.append("<html><tr><td>a");
site.append(dataReceived->data());
site.append("</td></tr></html>");
//tb->append(dataReceived->data());
tb->append(site);
//pixmap.loadFromData(dataReceived->data());
//label->setPixmap(pixmap);
}
}
void Image::done(bool error){
cout << "DONE function, bool reported:\n";
if(!error)
cout << "no error\n";
pixmap.loadFromData(dataReceived->data());
label->setPixmap(pixmap);
tb->append(dataReceived->data());
}
#include <QHttp>
#include <QHttpRequestHeader>
#include <QHttpResponseHeader>
#include <QByteArray>
#include <QLabel>
#include <QImage>
#include <QString>
#include <QTextBrowser>
#include <iostream>
#include "image.h"
using namespace std;
Image::Image(){
tb = new QTextBrowser(this);
dataReceived = new QByteArray();
dataReceived->clear();
label = new QLabel(this);
http = new QHttp("localhost", 80, this);
QHttpRequestHeader header("GET", "/images/test.jpg");
header.setValue("Host", "localhost");
http->setHost("localhost");
http->request(header);
connect(http, SIGNAL(readyRead(const QHttpResponseHeader &)), this, SLOT(getLogo(const QHttpResponseHeader &)));
connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(requestFinished(int, bool)));
//connect(http, SIGNAL(done(bool)), this, SLOT(done(bool)));
setFixedSize(300, 150);
setCentralWidget(label);
show();
}
void Image::getLogo(const QHttpResponseHeader & resp){
//QByteArray imageData(http->readAll());
//QImage image(imageData.data());
//QImage image("logo.png");
//label->setPixmap(QPixmap::fromImage(image));
cout << "The response:\n";
dataReceived->append(http->readAll());
cout << "dataReceived lenght: " << dataReceived->size() << endl;
//QString temp1 = dataReceived->data();
//cout << temp1.toStdString();
}
void Image::requestFinished(int n, bool error){
if(error){
cout << "requestFinished error\n";
}
else{
if(dataReceived->size()==0){
return;
}
cout << "requestFinished ok\n";
cout << "Image lenght: " << dataReceived->size() << endl;
site.append("<html><tr><td>a");
site.append(dataReceived->data());
site.append("</td></tr></html>");
//tb->append(dataReceived->data());
tb->append(site);
//pixmap.loadFromData(dataReceived->data());
//label->setPixmap(pixmap);
}
}
void Image::done(bool error){
cout << "DONE function, bool reported:\n";
if(!error)
cout << "no error\n";
pixmap.loadFromData(dataReceived->data());
label->setPixmap(pixmap);
tb->append(dataReceived->data());
}
To copy to clipboard, switch view to plain text mode
Bookmarks