IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QAbstractHttpServer Class

API to subclass to implement an HTTP server.

This class was introduced in Qt 6.4.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QAbstractHttpServer Class

  • Header: QAbstractHttpServer

  • Since: Qt 6.4

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS HttpServer)

    target_link_libraries(mytarget PRIVATE Qt6::HttpServer)

  • qmake: QT += httpserver

  • Inherits: QObject

  • Inherited By: QHttpServer

Detailed Description

Subclass this class and override handleRequest() to create an HTTP server. Use listen() or bind() to start listening to incoming connections.

Member Function Documentation

 

[explicit] QAbstractHttpServer::QAbstractHttpServer(QObject *parent = nullptr)

Creates an instance of QAbstractHttpServer with the parent parent.

void QAbstractHttpServer::bind(QTcpServer *server = nullptr)

Bind the HTTP server to given TCP server over which the transmission happens. It is possible to call this function multiple times with different instances of TCP server to handle multiple connections and ports, for example both SSL and non-encrypted connections.

After calling this function, every _new_ connection will be handled and forwarded by the HTTP server.

It is the user's responsibility to call QTcpServer::listen() on the server.

If the server is null, then a new, default-constructed TCP server will be constructed, which will be listening on a random port and all interfaces.

The server will be parented to this HTTP server.

See Also

bool QAbstractHttpServer::hasPendingWebSocketConnections() const

Returns true if the server has pending WebSocket connections; otherwise returns false.

See Also

quint16 QAbstractHttpServer::listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0)

Tries to bind a QTcpServer to address and port.

Returns the server port upon success, 0 otherwise.

void QAbstractHttpServer::newWebSocketConnection()

This signal is emitted every time a new WebSocket connection is available.

See Also

std::unique_ptr<QWebSocket> QAbstractHttpServer::nextPendingWebSocketConnection()

Returns the next pending connection as a connected QWebSocket object. nullptr is returned if this function is called when there are no pending connections.

The returned QWebSocket object cannot be used from another thread.

See Also

QList<quint16> QAbstractHttpServer::serverPorts()

Returns the list of ports this instance of QAbstractHttpServer is listening to.

This function has the same guarantee as QObject::children, the latest server added is the last entry in the vector.

See Also

See also servers()

QList<QTcpServer *> QAbstractHttpServer::servers() const

Returns list of child TCP servers of this HTTP server.

See Also

See also serverPorts()

void QAbstractHttpServer::sslSetup(const QSslCertificate &certificate, const QSslKey &privateKey, QSsl::SslProtocol protocol = QSsl::SecureProtocols)

Turns the server into an HTTPS server.

The next listen() call will use the given certificate, privateKey, and protocol.

void QAbstractHttpServer::sslSetup(const QSslConfiguration &sslConfiguration)

Turns the server into an HTTPS server.

The next listen() call will use the given sslConfiguration.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+