Собственно код (получаю html страницу):
#ifndef WEBS_H
#define WEBS_H
#include <QObject>
#include <QHttp>
#include <QUrl>
class Webs : public QObject
{
Q_OBJECT
public:
Webs();
QString getText();
private slots:
void httpRequestFinished(bool);
private:
QString text;
QHttp *http;
};
#endif
#include "webs.h"
Webs::Webs()
{
http = new QHttp();
connect(http, SIGNAL(done(bool)), this, SLOT(httpRequestFinished(bool)));
}
QString Webs::getText()
{
http->setHost(QUrl("http://crossplatform.ru").host(), QHttp::ConnectionModeHttp);
QByteArray path = QUrl::toPercentEncoding(QUrl("http://crossplatform.ru").path(), "!$&'()*+,;=:@/");
http->get(path);
return text;
}
void Webs::httpRequestFinished(bool error)
{
if (!error) {
text = http->readAll();
}
else
qDebug("Error!");
}
#include <QtGui>
#include <QLabel>
#include "webs.h"
int main(int argc, char *argv[])
{
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
QApplication app(argc, argv);
QLabel *win = new QLabel();
Webs *web = new Webs();
win->setText(web->getText());
win->show();
return app.exec();
}
TEMPLATE = app
INCLUDEPATH += .
QT += network
HEADERS += webs.h
SOURCES += webs.cpp main.cpp
Как в функции класса дождаться выполнения сигнала и вернуть уже загруженную страницу?
Сообщение отредактировал lioncub - 20.11.2009, 15:46