我特林建立一個客戶端的Web服務。我的目標是每秒向我的服務器發送請求。我用這個庫,幫助我:QHttp通QCoreApplication參數
我創建了一個定時器,我用的信號鏈接到我的QCoreApplication app
,並送我的請求時,計時器達到1秒。
這裏是我該怎麼辦呢:
的main.cpp
#include "request.h"
int main(int argc, char** argv) {
QCoreApplication app(argc, argv);
Request* request = new Request();
request->sendRequestPeriodically(1000, app);
return app.exec();
}
request.h
//lots of include before
class Request
{
Q_OBJECT
public:
Request();
void sendRequestPeriodically (int time, QCoreApplication app);
public slots:
void sendRequest (QCoreApplication app);
};
request.cpp
#include "request.h"
void Request::sendRequest (QCoreApplication app){
using namespace qhttp::client;
QHttpClient client(&app);
QUrl server("http://127.0.0.1:8080/?Clearance");
client.request(qhttp::EHTTP_GET, server, [](QHttpResponse* res) {
// response handler, called when the incoming HTTP headers are ready
// gather HTTP response data (HTTP body)
res->collectData();
// when all data in HTTP response have been read:
res->onEnd([res]() {
// print the XML body of the response
qDebug("\nreceived %d bytes of http body:\n%s\n",
res->collectedData().size(),
res->collectedData().constData()
);
// done! now quit the application
//qApp->quit();
});
});
// set a timeout for the http connection
client.setConnectingTimeOut(10000, []{
qDebug("connecting to HTTP server timed out!");
qApp->quit();
});
}
void Request::sendRequestPeriodically(int time, QCoreApplication app){
QTimer *timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(sendRequest(app)));
timer->start(time); //time specified in ms
}
Request::Request()
{
}
我得到了這些錯誤:
C:\Qt\5.7\mingw53_32\include\QtCore\qcoreapplication.h:211: erreur : 'QCoreApplication::QCoreApplication(const QCoreApplication&)' is private
Q_DISABLE_COPY(QCoreApplication)
C:\Users\ebelloei\Documents\qhttp\example\client-aircraft\main.cpp:7: erreur : use of deleted function 'QCoreApplication::QCoreApplication(const QCoreApplication&)'
我是新來的Qt,但我相信這來自於一個事實,我不能過時我QCoreApplication的參數,這是正確的?
非常強烈的答案,並理解我的問題。我記得在4年前在這裏問過一些問題,並從你那裏得到答案,謝謝你的工作。 –