Tutorial

Last changes

1.7.1 10.11.2016
Fixed a possible memory leak in case of broken Multipart HTTP Requests.

1.7.0 08.11.2016
Introduced namespace "stefanfrings".
Improved performance a little.

1.6.7 10.10.2016
Fix type of socketDescriptor in qtservice library.
Add support for INFO log messages (new since QT 5.5).
Improve indentation of log messages.

1.6.6 25.07.2016
Removed useless mutex from TemplateLoader.
Add mutex to TemplateCache (which is now needed).

1.6.5 10.06.2016
Incoming HTTP request headers are now processed case-insensitive.
Add support for the HttpOnly flag of cookies.

1.6.4 27.03.2016
Fixed constructor of Template class did not load the source file properly.
Template loader and cache were not affected.

1.6.3 11.03.2016
Fixed a compilation error.
Added missing implementation of HttpRequest::getPeerAddress().

1.6.2 06.03.2016
Added mime types for some file extensions.

1.6.1 25.01.2016
Fixed parser of boundary value in multi-part request, which caused that QHttpMultipart did not work on client side.

1.6.0 29.12.2015
Much better output buffering, reduces the number of small IP packages.

...

1.5.0 03.04.2015
Add support for HTTPS.

...

1.4.0 14.03.2015
Add support the creation of a shared library (*.dll or *.so).

...

1.3.0 20.04.2013
Add support for logging source file name, line number and function name.

...

1.2.0 05.12.2010
Add a controller that serves static files, with cacheing.

...

1.1.0 19.10.2010
Add support for sessions.

...

1.0.0 17.10.2010
First release

Start page    Deutsche Version dieser Seite

QtWebApp HTTP Webserver in C++

QtWepApp is a HTTP server library in C++, inspired by Java Servlets. For Linux, Windows, Mac OS and many other operating systems that the Qt Framework supports.

QtWebApp contains the following components

These components can be used independently of each other.

The HTTP server processes incoming requests in concurrent threads. It supports IPv4 and IPv6, persistent connections, HTTPS, session cookies, and file-uploads.

The multi-language capable template engine fills placeholders in text templates with runtime values. The template engine also supports conditional and repeatable blocks. Other larger template engines, such as ClearSilver, may be used as an alternative.

The logger plugs into Qt and writes log messages into files, while they are enriched with additional attributes like timestamp, thread ID, session ID and some more. Changes to the configuration file of the logger become active automatically without program restart.

The QtService component enables you to set up your application as a Windows Service.

The small memory requirement of about 2MB qualifies the web server to be used in embedded systems. For example the Beer brewing machine of Sebastian Düll. But it's also powerful enough for larger web services.

A very small example:

// The request handler receives and responds HTTP requests
void MyRequestHandler::service(HttpRequest& request, HttpResponse& response)
{
    // Get a request parameters
    QByteArray username=request.getParameter("username");

    // Set a response header
    response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");

    // Generate the HTML document
    response.write("<html><body>");
    response.write("Hello ");
    response.write(username);
    response.write("</body></html>");
}

// The main program starts the HTTP server
int main(int argc, char *argv[])
{
    QCoreApplication* app=new QCoreApplication(argc,argv);
        
    QSettings* settings=new QSettings("configfile.ini",QSettings::IniFormat,app);
    MyRequestHandler* handler=new MyRequestHandler(app);
    HttpListener* listener=new HttpListener(settings,handler,app);

    return app->exec();
}

You may download QtWebApp.zip for free and use the software under the conditions of the LGPL License. The Tutorial explains how to use the library. And here is the API documentation .

Thanks

The current high quality of the program is not only the result of my own work. Some people tested the program in production environments and suggested improvements. I'm thankful for their help.