views:

693

answers:

4

Hello,

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.

+2  A: 

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.

extraneon
I honestly don't want to do anything layout related in my application (as that's what template classes and such are for). I just want to exchange essential information between the web server and my core application and use more stable and secure technology to do the rest. Never looked at SOAP, gonna read a bit more about that.
BastiBense
+2  A: 

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

Mihai Limbășan
I looked into FastCGI, but the "official" C/C++ library is a real mess. Maybe I missed something, but most web servers connect to the fastcgi applications using TCP/IP; although the official fastcgi library does not provide any TCP/IP support...?
BastiBense
A: 

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.

raffel
A: 

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.