StupidBeauty
Read times:532Posted at:Mon Feb 25 17:34:27 2013
- no title specified

转载How to create a simple webservice using qt and libqxt

使用postEvent(new QxtWebPageEvent(event->sessionID,event->requestID,DEFAULT_MESSAGE));来向客户端发送应答。

https://sites.google.com/a/embeddedlab.org/community/technical-articles/qt/qt-posts/howtocreateasimplewebserviceusingqtandlibqxt

亮点

void WebService::indexRequested(QxtWebRequestEvent *event)

{

qDebug() << "Request Headers: ";

QHash::const_iterator i = event->headers.constBegin();

while (i != event->headers.constEnd()) {

qDebug() << i.key() << ": " << i.value();

++i;

}

if (event->method.compare("POST")==0) {

QxtWebContent *myContent = event->content;

qDebug() << "Bytes to read: " << myContent->unreadBytes();

myContent->waitForAllContent();

QByteArray requestContent = myContent->readAll();

qDebug() << "Content: ";

qDebug() << requestContent;

parser->parseSOAP(requestContent);

QString num1 = parser->getNumber1();

QString num2 = parser->getNumber2();

QString sum;

if (num1!="" && num2!="") {

sum.setNum(num1.toInt()+num2.toInt());

QString bodyMessage = buildResponse(sum,"add");

qDebug() << bodyMessage;

postEvent(newQxtWebPageEvent(event->sessionID,

event->requestID,

bodyMessage.toUtf8()));

} else {

QString errorXml = buildResponse("0","add");

postEvent(new QxtWebPageEvent(event->sessionID,

event->requestID,

errorXml.toUtf8()));

}

} else if (event->method.compare("GET")==0) {

postEvent(new QxtWebPageEvent(event->sessionID,

event->requestID,

DEFAULT_MESSAGE));

}

}

乌坎村投票

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4