Deutsche Version dieser Seite

Last changes

1.8.6 30.09.2022
Fix compile error under Windows: sslCaCertFileName was not declared

1.8.5 19.03.2022
Add support for SSL peer verification and CA certificate.

1.8.4 29.10.2021
Add Content-Length header to static file controller.

1.8.3 21.03.2021
The minLevel for logging can now be configured as string.
Info messages are now positioned between DEBUG and WARNING.
I also added an example for HTTP Basic authorization.

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. A very small usage example:

// 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();
}


// 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=UTF-8");

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

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.

The logger improves disk space and performance by retaining debug messages in memory until an error occurs. No debug messages are written as long everything works fine. Changes to the configuration of the logger become active automatically without program restart.

Source code, Tutorial, API documentation .

The library runs with Qt version 4.7 to 6.x. In case of Qt 6 you need to install the Qt5Compat library. It contains support for a lot of 8 Bit character encodings, that Qt6 does not support anymore by default. You may use the software under the conditions of the LGPL License.

How it started

Many years ago a very experienced Java developer insisted that Java is the internet language, because doing internet communication is much more complicated in older programming languages. I replied that this is not correct, but he refused to believe me. So we started a challenge. Quest: After a weekend, we both presented what we achieved so far. Both programs were quite similar, so he admitted that he was wrong. By the way, the Qt/C++ program was much smaller and a bit faster than his Java version.

A few years later I made a library from that prototype and used it in some few private projects. Collegues encouraged me to publish the code. Since then I had no use of the project anymore, but I applied some improvements anyway to make people happy. Interestingly the Qt makers are working on a standard HTTP server since many years, but in 2022 it is still not included in the Qt library. That might explain why many people use my library instead.

Thanks

The current high quality of the library is the result of the collaboration of many people. I thank the helpers for testing QtWebApp extensively in a real productive environment and thus contributing to the improvement.