12345678910111213141516171819202122232425262728293031323334353637 |
- #include "helloworld.h"
- #include <QCoreApplication>
- #include <qhttpserver.h>
- #include <qhttprequest.h>
- #include <qhttpresponse.h>
- /// HelloWorld
- HelloWorld::HelloWorld()
- {
- QHttpServer *server = new QHttpServer(this);
- connect(server, SIGNAL(newRequest(QHttpRequest*, QHttpResponse*)),
- this, SLOT(handleRequest(QHttpRequest*, QHttpResponse*)));
- server->listen(QHostAddress::Any, 8080);
- }
- void HelloWorld::handleRequest(QHttpRequest *req, QHttpResponse *resp)
- {
- Q_UNUSED(req);
- QByteArray body = "Hello World";
- resp->setHeader("Content-Length", QString::number(body.size()));
- resp->writeHead(200);
- resp->end(body);
- }
- /// main
- int main(int argc, char **argv)
- {
- QCoreApplication app(argc, argv);
- HelloWorld hello;
- app.exec();
- }
|