Deutsche Version dieser Seite

Tutorial

Last changes

1.7.8 05.02.2019
HttpConnectionHandler closes the socket now in the thread of the socket.
Headers and Body sent to the browser are now separated into individual ethernet packets.

1.7.7 04.02.2019
HttpConnectionHandler creates a new Qthread instead of being itself a QThread.
Improved formatting of thread ID in logger.

1.7.6 18.01.2019
Code cleanup with const keywords and type conversions.
Update Documentation.

1.7.5 17.01.2019
Added content-types for *.xml and *.json to the StaticFileController.
Fixed locking and memory leak in HttpSession

1.7.4 24.05.2018
Fixed two possible null-pointer references in case of broken HTTP requests.

1.7.3 25.04.2017
Wait until all data are sent before closing connections.

1.7.2 17.01.2017
Fixed compile error with MSVC.

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.

Start page  

QtWebApp HTTP Server 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 parallel threads. It supports IPv4 and IPv6, persistent connections, HTTPS, session cookies, and file-uploads.

The template engine is helpful to generate websites which are based on template files by filling placeholders with data. It supports many languages and may be used for any text based file format (e.g. HTML, XML, CSV, ...). Other larger template engines, such as ClearSilver, may be used as well.

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. A ring-buffer adds details with debug level to error messages, without the need to output them permanently.

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(argc,argv);
        
    new HttpListener(
        new QSettings("configfile.ini",QSettings::IniFormat,&app),
        new MyRequestHandler(&app),
        &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 library is the result of the collaboration of many people. I would like to thank the helpers for testing QtWebApp extensively in a productive environment and thus contributing to the improvement.