Qt HTTP Server Registro

El Qt HTTP Server registra usando la clase QLoggingCategory. Las categorías de registro que comienzan con "qt.httpserver" son utilizadas por las diferentes partes del Servidor Http Qt. Estas pueden ser habilitadas y deshabilitadas como se describe en QLoggingCategory.

Para habilitar o deshabilitar dinámicamente lo que se está registrando llame a QLoggingCategory::setFilterRules(). Un servidor puede añadir una URL para cambiar las reglas de filtrado, usando la función QHttpServer::route() como se muestra a continuación.

#include <QCoreApplication>
#include <QHttpServer>
#include <QLoggingCategory>

int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);
    QHttpServer server;
    auto tcpserver = std::make_unique<QTcpServer>();
    if (!tcpserver->listen(QHostAddress::LocalHost, 8000) || !server.bind(tcpserver.get()))
        return -1;
    tcpserver.release();

    server.route("/loggingFilter", [] (const QHttpServerRequest &request) {
        QString filter;
        QTextStream result(&filter);
        for (auto pair : request.query().queryItems()) {
            if (!filter.isEmpty())
                result << "\n";
            result << pair.first << "=" << pair.second;
        }
        QLoggingCategory::setFilterRules(filter);
        return filter;
    });

    return app.exec();
}

Las reglas de filtrado pueden establecerse ahora utilizando: "http://127.0.0.1:8000/loggingFilter?qt.httpserver=true&appname.access=true". En este caso se habilitarán todos los registros de Qt HTTP Server, y además se habilita la hipotética categoría de registro appname.access.

Véase también QLoggingCategory y QHttpServer.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.