#include <QApplication>
#include <QHttp>
{
Q_OBJECT
public:
{
_http
= new QHttp( "www.xxx.zzz",
80,
this );
connect( _http, SIGNAL( requestFinished( int, bool )), this, SLOT( finished( int, bool ) ) );
connect( _http, SIGNAL( done(bool) ), this, SLOT( done(bool) ) );
start();
};
private slots:
void start()
{
int id = _http->get( "/" );
qWarning( "start id=%d", id );
}
void done( bool error )
{
qWarning("done: %d", error );
qWarning("error: %s", qPrintable( _http->errorString() ) );
// start();
}
void finished( int id, bool error )
{
qWarning("finished: %d %d ", id, error );
start();
}
void read( const QHttpResponseHeader& header )
{
qWarning( "code: %d, reason: %s", header.statusCode(), qPrintable( header.reasonPhrase() ) );
qWarning( _http->readAll() );
}
private:
};
int main( int argc, char **argv )
{
Test t;
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QHttp>
class Test : public QObject
{
Q_OBJECT
public:
Test() : QObject( 0 )
{
_http = new QHttp( "www.xxx.zzz", 80, this );
connect( _http, SIGNAL( readyRead( const QHttpResponseHeader & ) ), this, SLOT( read( const QHttpResponseHeader & ) ) );
connect( _http, SIGNAL( requestFinished( int, bool )), this, SLOT( finished( int, bool ) ) );
connect( _http, SIGNAL( done(bool) ), this, SLOT( done(bool) ) );
start();
};
private slots:
void start()
{
int id = _http->get( "/" );
qWarning( "start id=%d", id );
}
void done( bool error )
{
qWarning("done: %d", error );
qWarning("error: %s", qPrintable( _http->errorString() ) );
// start();
}
void finished( int id, bool error )
{
qWarning("finished: %d %d ", id, error );
start();
}
void read( const QHttpResponseHeader& header )
{
qWarning( "code: %d, reason: %s", header.statusCode(), qPrintable( header.reasonPhrase() ) );
qWarning( _http->readAll() );
}
private:
QHttp *_http;
};
int main( int argc, char **argv )
{
QApplication app( argc, argv );
Test t;
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks