在C ++/Qt(充当服务器)中创建提供JSON数据的简单WebService [英] Creating simple WebService in C++ / Qt (acting as server) providing JSON data

查看:607
本文介绍了在C ++/Qt(充当服务器)中创建提供JSON数据的简单WebService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个简单的Web服务(即服务器").目的是提供一些我在Qt/C ++应用程序中确实读取过的数据,作为 JSON 数据.基本上,浏览器中的JavaScript应用程序应从Qt应用程序读取其数据.通常这是一个单用户方案,因此用户在其浏览器中运行Google Maps应用程序,而其他数据则来自Qt应用程序.

I need to create a simple web service (being the "server"). The goal is to provide some data I do read in an Qt / C++ application as JSON data. Basically a JavaScript application in the browser shall read its data from the Qt app. It is usually a single user scenario, so the user runs a Google Maps application in her browser, while additional data come from the Qt application.

到目前为止,我已经找到了这些库:

So far I have found these libs:

  1. Qxt: http://libqxt.bitbucket.org/doc/0.6/index .html ,但是作为C ++/Qt的新手,我想念一些示例.补充:我在这里找到了一个示例
  2. gSoap: http://www.cs.fsu.edu/~engelen /soap.html 有更多示例和文档,并且似乎还支持JSON
  3. KD SOAP: http://www.kdab.com/kdab-products /kd-soap/据我所知,没有示例,docu是 http://qt-project.org/videos/watch/qt-networking-web-services
  1. Qxt: http://libqxt.bitbucket.org/doc/0.6/index.html but being a newbie on C++/Qt I miss some examples. Added: I have found one example here
  2. gSoap: http://www.cs.fsu.edu/~engelen/soap.html has more examples and documentation and also seems to support JSON
  3. KD SOAP: http://www.kdab.com/kdab-products/kd-soap/ with no example as far as I can tell, docu is here
  4. Qt features itself, but it is more about acting as a client: http://qt-project.org/videos/watch/qt-networking-web-services

检查SO基本上可以得到上述库的链接

Checking SO gives me basically links to the above libs

  1. 带有Qt的Web服务,但我并没有得到一个示例.
  2. 如何通过Qt创建Web服务
  1. webservice with Qt with an example I do not really get.
  2. How to Create a webservice by Qt

所以基本上我确实有以下问题:

  1. 您将使用哪个lib?我想使其尽可能简单,并且需要一个例子.
  2. 除了WebService之外,还有另一种(简单!)向JSON网页提供JSON数据的方法吗?

-编辑,备注:---

-- Edit, remarks: ---

需要是应用程序固有的.无法安装Web服务器,无法使用额外的运行时间.用户仅运行该应用程序.也许Qt WebKit可能是一种方法....

Needs to be application intrinsic. No web server can be installed, no extra run time can be used. The user just runs the app. Maybe the Qt WebKit could be an approach....

-编辑2-

当前正在从SO开始检查小型Web服务器" Qt HTTP Server?"

Currently checking the tiny web servers as of SO " Qt HTTP Server? "

推荐答案

截至我的测试,当前我正在使用QtWebApp: http://stefanfrings.de/qtwebapp/index-en.html 这是Edit 2(

As of my tests, currently I am using QtWebApp: http://stefanfrings.de/qtwebapp/index-en.html This is one of the answers of Edit 2 ( Qt HTTP Server? )

Stefan的小型WebServer具有一些文档齐全的代码,用"Qt C ++"编写,并且易于使用,特别是如果您已经使用过servlet.由于可以轻松地将其集成到我的Qt项目中,因此我将获得一个内部WebServer.

Stefan's small WebServer has some well documented code, is written in "Qt C++" and easy to use, especially if you have worked with servlets already. Since it can be easily integrated in my Qt project, I'll end up with an internal WebServer.

我的JSON测试中的一些演示代码,表明生成JSON内容基本上是在创建QString.

Some demo code from my JSON tests, showing that generating the JSON content is basically creating a QString.

void WebServiceController::service(HttpRequest& request, HttpResponse& response) {
// set some headers
response.setHeader("Content-Type", "application/json; charset=ISO-8859-1");
response.setCookie(HttpCookie("wsTest","CreateDummyPerson",600));

QString dp = WebServiceController::getDummyPerson();
QByteArray ba = dp.toLocal8Bit();
const char *baChar = ba.data();
response.write(ba);
}

如果有人可以轻松地与其他库共享示例,请告诉我.

If someone has easy examples with other libs to share, please let me know.

这篇关于在C ++/Qt(充当服务器)中创建提供JSON数据的简单WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆