QHttpEngine 0.1.0
Simple and secure HTTP server for Qt applications
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
QObjectHandler Class Reference

Handler for invoking slots. More...

#include <QHttpEngine/QObjectHandler>

Inheritance diagram for QObjectHandler:
QHttpHandler

Public Member Functions

 QObjectHandler (QObject *parent=0)
 Create a new QObject handler.
 
- Public Member Functions inherited from QHttpHandler
 QHttpHandler (QObject *parent=0)
 Base constructor for a handler.
 
void addRedirect (const QRegExp &pattern, const QString &path)
 Add a redirect for a specific pattern.
 
void addSubHandler (const QRegExp &pattern, QHttpHandler *handler)
 Add a handler for a specific pattern.
 
void route (QHttpSocket *socket, const QString &path)
 Route an incoming request.
 

Protected Member Functions

virtual void process (QHttpSocket *socket, const QString &path)
 Reimplementation of QHttpHandler::process()
 

Detailed Description

This handler enables incoming requests to invoke a matching slot in a QObject-derived class. The request body is expected to contain parameters encoded as a JSON object. This object is then passed to the slot as a single QVariantMap argument. The slot should return a QVariantMap containing the response.

To use this class, it must be subclassed and one or more slots must be created. The name of the slot will be used to determine the path. For example, the following handler consists of a single method that can be invoked by using the /doSomething path.

class TestHandler : public QObjectHandler
{
Q_OBJECT
private slots:
QVariantMap doSomething(QVariantMap params);
};
Handler for invoking slots.
Definition qobjecthandler.h:61

The request body must contain valid JSON which will be decoded and passed to the doSomething() slot as a QVariantMap. The slot should return a QVariantMap which will then be encoded as JSON and written to the socket as the response body.

Member Function Documentation

◆ process()

virtual void QObjectHandler::process ( QHttpSocket socket,
const QString &  path 
)
protectedvirtual

Reimplemented from QHttpHandler.


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