void Downloader::doDownload()
{
http->setHost("c-studios.host56.com");
http->get("/index.html");
connect(http, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
}
// ....
{
qDebug() << "Size: " << resp.contentLength(); //works fine. show correct length
qDebug() << "Type: " << resp.contentType(); // works fine
qDebug() << "Status: " << resp.statusCode(); // fine return 200
}
void Downloader::requestFinished(int id, bool error)
{
if(error)
{
qDebug() << "Error!";
}
else
{
qDebug() << "Ok!";
}
}
void Downloader::showHtml()
{
QString html
(http
->readAll
());
//this is the problem. QString is empty qDebug() << html;
}
void Downloader::doDownload()
{
QHttp *http = new QHttp(this);
http->setHost("c-studios.host56.com");
http->get("/index.html");
connect(http, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(responseHeaderReceived(QHttpResponseHeader)));
connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
connect(http, SIGNAL(readyRead(QHttpResponseHeader)), this, SLOT(showHtml()));
}
// ....
void Downloader::responseHeaderReceived(const QHttpResponseHeader &resp)
{
qDebug() << "Size: " << resp.contentLength(); //works fine. show correct length
qDebug() << "Type: " << resp.contentType(); // works fine
qDebug() << "Status: " << resp.statusCode(); // fine return 200
}
void Downloader::requestFinished(int id, bool error)
{
if(error)
{
qDebug() << "Error!";
}
else
{
qDebug() << "Ok!";
}
}
void Downloader::showHtml()
{
QString html(http->readAll()); //this is the problem. QString is empty
qDebug() << html;
}
To copy to clipboard, switch view to plain text mode
Bookmarks