QHttpEngine 1.0.1
Simple and secure HTTP server for Qt applications
Loading...
Searching...
No Matches
QHttpEngine::QObjectHandler Class Reference

Handler for invoking slots More...

#include <qhttpengine/qobjecthandler.h>

Inheritance diagram for QHttpEngine::QObjectHandler:
QHttpEngine::Handler

Public Member Functions

 QObjectHandler (QObject *parent=0)
 Create a new QObject handler.
void registerMethod (const QString &name, Functor functor, bool readAll=true)
 Register a method.
void registerMethod (const QString &name, QObject *receiver, const char *method, bool readAll=true)
 Register a method.
void registerMethod (const QString &name, QObject *receiver, Functor functor, bool readAll=true)
 Register a method.
void registerMethod (const QString &name, QObject *receiver, PointerToMemberFunction method, bool readAll=true)
 Register a method.
Public Member Functions inherited from QHttpEngine::Handler
 Handler (QObject *parent=0)
 Base constructor for a handler.
void addMiddleware (Middleware *middleware)
 Add middleware to the handler.
void addRedirect (const QRegExp &pattern, const QString &path)
 Add a redirect for a specific pattern.
void addSubHandler (const QRegExp &pattern, Handler *handler)
 Add a handler for a specific pattern.
void route (Socket *socket, const QString &path)
 Route an incoming request.

Protected Member Functions

virtual void process (Socket *socket, const QString &path)
 Reimplementation of [Handler::process()](QHttpEngine::Handler::process)

Friends

class QObjectHandlerPrivate

Detailed Description

This handler enables incoming requests to be processed by slots in a QObject-derived class or functor. Methods are registered by providing a name and slot to invoke. The slot must take a pointer to the Socket for the request as an argument and must also close the socket when finished with it.

To use this class, simply create an instance and call the appropriate registerMethod() overload. For example:

class Object : public QObject
{
Q_OBJECT
public slots:
void something(QHttpEngine::Socket *socket);
};
Object object;
// Old connection syntax
handler.registerMethod("something", &object, SLOT(something(QHttpEngine::Socket*)));
// New connection syntax
handler.registerMethod("something", &object, &Object::something);
Handler for invoking slots
Definition qobjecthandler.h:77
void registerMethod(const QString &name, QObject *receiver, const char *method, bool readAll=true)
Register a method.
Implementation of the HTTP protocol.
Definition socket.h:97

It is also possible to use this class with a functor, eliminating the need to create a class and slot:

handler.registerMethod("something", [](QHttpEngine::Socket *socket) {
// do something
socket->close();
});
virtual void close()
Close the device and underlying socket.

Member Function Documentation

◆ process()

virtual void QHttpEngine::QObjectHandler::process ( Socket * socket,
const QString & path )
protectedvirtual

Reimplemented from QHttpEngine::Handler.

◆ registerMethod() [1/4]

void QHttpEngine::QObjectHandler::registerMethod ( const QString & name,
Functor functor,
bool readAll = true )

This overload uses the new functor syntax (without context).

◆ registerMethod() [2/4]

void QHttpEngine::QObjectHandler::registerMethod ( const QString & name,
QObject * receiver,
const char * method,
bool readAll = true )

This overload uses the traditional connection syntax with macros.

The readAll parameter determines whether all data must be received by the socket before invoking the slot.

◆ registerMethod() [3/4]

void QHttpEngine::QObjectHandler::registerMethod ( const QString & name,
QObject * receiver,
Functor functor,
bool readAll = true )

This overload uses the new functor syntax (with context).

◆ registerMethod() [4/4]

void QHttpEngine::QObjectHandler::registerMethod ( const QString & name,
QObject * receiver,
PointerToMemberFunction method,
bool readAll = true )

This overload uses the new connection syntax with member pointers.


The documentation for this class was generated from the following file: