Mercurial > hg > svapp
changeset 263:3c236d31cccd qt5
Get this one building with Qt5
author | Chris Cannam |
---|---|
date | Mon, 11 Mar 2013 14:48:49 +0000 |
parents | 8a603a0840c8 |
children | 518b2cbd6bf2 |
files | framework/VersionTester.cpp framework/VersionTester.h svapp.pro |
diffstat | 3 files changed, 35 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/VersionTester.cpp Fri Nov 16 13:09:58 2012 +0000 +++ b/framework/VersionTester.cpp Mon Mar 11 14:48:49 2013 +0000 @@ -23,24 +23,30 @@ #include <iostream> -#include <QHttp> +#include <QNetworkAccessManager> + +static QNetworkAccessManager nm; VersionTester::VersionTester(QString hostname, QString versionFilePath, QString myVersion) : - m_httpFailed(false), - m_myVersion(myVersion) + m_myVersion(myVersion), + m_reply(0), + m_httpFailed(false) { - QHttp *http = new QHttp(); - connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), - this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &))); - connect(http, SIGNAL(done(bool)), - this, SLOT(httpDone(bool))); - http->setHost(hostname); - http->get(versionFilePath); + QUrl url(QString("http://%1/%2").arg(hostname).arg(versionFilePath)); + std::cerr << "VersionTester: URL is " << url << std::endl; + m_reply = nm.get(QNetworkRequest(url)); + connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(error(QNetworkReply::NetworkError))); + connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); } VersionTester::~VersionTester() { + if (m_reply) { + m_reply->abort(); + m_reply->deleteLater(); + } } bool @@ -69,20 +75,25 @@ } void -VersionTester::httpResponseHeaderReceived(const QHttpResponseHeader &h) +VersionTester::error(QNetworkReply::NetworkError) { - if (h.statusCode() / 100 != 2) m_httpFailed = true; + std::cerr << "VersionTester: error: " << m_reply->errorString() << std::endl; + m_httpFailed = true; } void -VersionTester::httpDone(bool error) +VersionTester::finished() { - QHttp *http = const_cast<QHttp *>(dynamic_cast<const QHttp *>(sender())); - if (!http) return; - http->deleteLater(); - if (error || m_httpFailed) return; + m_reply->deleteLater(); + if (m_httpFailed) return; - QByteArray responseData = http->readAll(); + int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (status / 100 != 2) { + std::cerr << "VersionTester: error: http status = " << status << std::endl; + return; + } + + QByteArray responseData = m_reply->readAll(); QString str = QString::fromUtf8(responseData.data()); QStringList lines = str.split('\n', QString::SkipEmptyParts); if (lines.empty()) return;
--- a/framework/VersionTester.h Fri Nov 16 13:09:58 2012 +0000 +++ b/framework/VersionTester.h Mon Mar 11 14:48:49 2013 +0000 @@ -24,8 +24,7 @@ #include <QStringList> #include <QString> #include <QObject> - -class QHttpResponseHeader; +#include <QNetworkReply> class VersionTester : public QObject { @@ -41,12 +40,13 @@ void newerVersionAvailable(QString); protected slots: - void httpResponseHeaderReceived(const QHttpResponseHeader &); - void httpDone(bool); + void finished(); + void error(QNetworkReply::NetworkError); private: + QString m_myVersion; + QNetworkReply *m_reply; bool m_httpFailed; - QString m_myVersion; }; #endif