#include <QNetworkAccessManager>
#include <QCoreApplication>
#include <QTimer>
#include <QtDebug>
class ServiceConnector
: public QObject { Q_OBJECT
public:
connect(&m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processResult(QNetworkReply*)));
connect(&m_timer, SIGNAL(timeout()), this, SLOT(nextQuery()));
}
public slots:
void start(int ms = 1000) {
m_timer.start(ms);
}
private slots:
void nextQuery() {
m_manager.get(QNetworkRequest(m_url));
}
void processResult(QNetworkReply *reply) {
qDebug() << reply->readAll();
reply->deleteLater();
}
private:
QNetworkAccessManager m_manager;
};
#include "main.moc"
int main(int argc, char **argv) {
ServiceConnector connector("your webservice url");
connector.start(1000);
return app.exec();
}
#include <QNetworkAccessManager>
#include <QCoreApplication>
#include <QTimer>
#include <QtDebug>
class ServiceConnector : public QObject {
Q_OBJECT
public:
ServiceConnector(const QUrl &url, QObject *parent = 0) : QObject(parent), m_url(url) {
connect(&m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processResult(QNetworkReply*)));
connect(&m_timer, SIGNAL(timeout()), this, SLOT(nextQuery()));
}
public slots:
void start(int ms = 1000) {
m_timer.start(ms);
}
private slots:
void nextQuery() {
m_manager.get(QNetworkRequest(m_url));
}
void processResult(QNetworkReply *reply) {
qDebug() << reply->readAll();
reply->deleteLater();
}
private:
QNetworkAccessManager m_manager;
QUrl m_url;
QTimer m_timer;
};
#include "main.moc"
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
ServiceConnector connector("your webservice url");
connector.start(1000);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks