使用 C++/Qt4 应用程序作为 Web 应用程序的后端

发布于 2024-08-22 04:30:27 字数 1031 浏览 4 评论 0原文

对于我的一个应用程序,我想提供一个最小的 Web 界面。这个核心应用程序是用C++编写的,并使用Qt4作为框架。由于我还使用我编写的一些库来计算一些事情并进行一些复杂的数据管理,因此我想使用此现有代码作为 Web 界面的后端。

想法 1:使用嵌入式 Web 服务器

我尝试的第一件事(并且在某种程度上有效)是使用嵌入式 Web 服务器 (猫鼬)。正如你可以想象的,它只是一个非常薄的库,你必须自己实现很多东西(比如会话管理、cookie 等)。

想法 2:使用普通的 Web 服务器并向我的应用程序添加 fcgi/cgi/scgi 后端

我想到的下一件事是使用成熟但紧凑的 Web 服务器(例如,lighttpd)和简单地为其提供一个 fcgi/scgi/cgi 后端。我可以使用良好的框架(例如 Pylons、PHP 或 RoR,(...))编写 Web 应用程序,并且只需要一个 URL 前缀,例如 /a/...,它允许我直接与后端对话。

我尝试在我的应用程序中实现 libfcgi,但它看起来比需要的更混乱(例如,您必须实现自己的 TCP/IP 套接字才能在您的应用程序和 Web 服务器之间传递数据,并通过 FCGI 库对其进行隧道传输, meh)

想法 3:创建应用程序的命令行版本,它执行最基本的操作,并使用普通的 Web 服务器和框架来完成其余操作

这是我想到的第三个想法。它基本上是使用传统方式(PHP、RoR 等)创建 Web 应用程序,并使用应用程序的命令行版本来处理数据并在需要时返回数据。


我在创建 Web 应用程序方面有一些经验,但我从来没有做过这样的事情,所以我想听听一些想法或建议。我想在浏览器上使用 JavaScript(即 AJAX),并在 Web 浏览器和服务器之间传递一些 JSON 结构,以使用户体验更加流畅。

那么您对此有何建议、想法?老实说,我不想重新发明轮子。

for one of my applications I'd like to provide a minimal web interface. This core application is written in C++ and uses Qt4 as a framework. Since I'm also using some libraries I wrote to calculate some things and do some complex data management, I'd like to use this existing code as a backend to the web interface.

Idea 1: Using an embedded web server

The first thing I tried (and which worked to some degree) was using an embedded web server (mongoose). As you can imagine, it is just a very thin library and you have to implement a lot of things yourself (like session management, cookies, etc.).

Idea 2: Using a normal web server and adding a fcgi/cgi/scgi backend to my application

The next thing that came to my head was using a mature but compact web server (for instance, lighttpd) and simple provide a fcgi/scgi/cgi backend to it. I could write the web application using a good framework, like Pylons, PHP, or RoR, (...) and simply have an URL prefix, like /a/... which allows me to directly talk to the backend.

I tried to implement the libfcgi into my application, but it looks messier than needed (for instance you'd have to implement your own TCP/IP sockets to pass on data between your app and the web server and tunnel it through the FCGI library, meh)

Idea 3: Creating a command line version of my application which does the most basic things and use a normal web server and framework to do the rest

This is the third idea that came to my head. It is basically about creating a web application using a traditional way (PHP, RoR, etc.) and using a command line version of my application to process data and return it when needed.


I've got some experience with creating web applications, but I never had to do something like this, so I'd like to hear some ideas or suggestions. I'd like to use JavaScript on the browsers (AJAX, that is) and pass some JSON constructs between web browser and server to make the user experience a bit smoother.

So what are your suggestions, ideas on this? I don't want to re-invent the wheel, honestly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

燕归巢 2024-08-29 04:30:27

我永远不会将自定义编写的应用程序作为前端暴露给网络,因为像 apache 或 lighthttp 这样的服务器是构建的。它们为您提供了一些开箱即用的严格安全性。

至于您的应用程序与该网络服务器的交互,这在一定程度上取决于负载以及您使用 PHP、Python 或网络服务器支持的其他语言(当然通过解释器)编写软件的经验。

轻微的负载,从 PHP 访问的命令行工具可能会做得很好。

负载更重,您可能希望使用 Qt 实现一个简单的(SOAP?)服务器并从 python(或 php)脚本访问它。

这样您就不需要在应用程序中进行布局,也不需要实现太多的安全性。

I would never expose a custom written application to the net as front-end, for that servers like apache or lighthttp are build. They give you some serious security out of the box.

As for interaction of your app with that webserver, it depends a bit on the load and what kind of experience you have with writing software in PHP, python or other languages supported by your web server (via interpreter of course).

A slight load, and a command line tool accessed from PHP might do perfectly well.

A more heavy load and you might wish to implement a simple (SOAP?) server with Qt and access that from a python (or php) script.

That way you don't need to do layout in you app, and you also don't need to implement security all that much.

残月升风 2024-08-29 04:30:27

我目前正在研究类似的情况(使用 Qt 的自定义 Web 应用程序后端),最不坏的选择是 FastCGI。找到了您可能感兴趣的东西。如果没有进行一些认真的测试,还没有准备好生产,但这可能是 Qt - FastCGI 互操作的一个很好的起点:FastCGIQt

I'm currently researching a similar situation (custom web app backend using Qt), and the least bad option is FastCGI. Found something you might be interested in. Not production ready without some serious testing, but this might be a good starting point for Qt - FastCGI interop: FastCGIQt

浪漫人生路 2024-08-29 04:30:27

我在类似的项目(也是 Qt 应用程序)中使用了 FastCGI 协议驱动程序库,下载链接位于该页面的末尾 [Libfastcgi]。与应用程序的集成实际上相对容易。 Lighttpd + mod_fastcgi 用作​​ Web 服务器。不过,不能对 FastCGIQt 说什么。

I've used the FastCGI Protocol Driver library for a similar project (also a Qt application), the download link is at the end of that page [Libfastcgi]. Integration with the application turned out actually comparatively easy. Lighttpd + mod_fastcgi was used as web server. Can't say anything about FastCGIQt, though.

⒈起吃苦の倖褔 2024-08-29 04:30:27

Wt 可以很好地为基于 Qt 的应用程序提供 Web 界面。两者具有相似的编程风格,并且有一个示例演示了与 Qt 的集成。

You Wt works well to provide a web interface to Qt based applications. Both have a similar programming style, and there's an example that demonstrates the integration with Qt.

若水般的淡然安静女子 2024-08-29 04:30:27

以下是嵌入式 QML 服务器的示例: https://github.com/ncp1402/ql-server

Here is example of embedded QML-server: https://github.com/ncp1402/ql-server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文