Cutelyst  1.8.0
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
Cutelyst::Application Class Reference

The Cutelyst Application. More...

#include <Cutelyst/Application>

Inheritance diagram for Cutelyst::Application:
Inheritance graph


void afterDispatch (Context *c)
void beforeDispatch (Context *c)
void beforePrepareAction (Context *c, bool *skipMethod)
void postForked (Application *app)
void preForked (Application *app)

Public Member Functions

 Application (QObject *parent=nullptr)
void addTranslator (const QLocale &locale, QTranslator *translator)
void addTranslator (const QString &locale, QTranslator *translator)
void addTranslators (const QLocale &locale, const QVector< QTranslator * > &translators)
QVariant config (const QString &key, const QVariant &defaultValue=QVariant()) const
QVariantMap config () const
QVector< Controller * > controllers () const
ComponentcreateComponentPlugin (const QString &name, QObject *parent=nullptr)
Dispatcherdispatcher () const
QVector< DispatchType * > dispatchers () const
Engineengine () const
bool inited () const
QString pathTo (const QString &path) const
QString pathTo (const QStringList &path) const
template<typename T >
plugin ()
 Returns the registered plugin that casts to the template type T.
QVector< Plugin * > plugins () const
QString translate (const QLocale &locale, const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Viewview (const QString &name=QString()) const

Static Public Member Functions

static const char * cutelystVersion ()

Protected Member Functions

HeadersdefaultHeaders ()
bool enginePostFork ()
 Called by the Engine once post fork happened.
Q_DECL_DEPRECATED void handleRequest (Request *req)
 Called by the Engine to handle a new Request object.
ContexthandleRequest2 (Request *req)
 Called by the Engine to handle a new Request object.
virtual bool init ()
virtual bool postFork ()
bool registerController (Controller *controller)
bool registerDispatcher (DispatchType *dispatcher)
bool registerPlugin (Plugin *plugin)
bool registerView (View *view)
void setConfig (const QString &key, const QVariant &value)
bool setup (Engine *engine)
 Called by the Engine to setup the internal data.


class Engine

Detailed Description

This is the main class of a Cutelyst appplication

Definition at line 56 of file application.h.

Constructor & Destructor Documentation

Cutelyst::Application::Application ( QObject *  parent = nullptr)

The constructor is used to setup the class configuration, subclasses should only use this for objects that do not require configuration to be ready.

A Web Engine will instantiate your application through this class, next it will load the settings file, and in the end it will call init() which is where your application should do it's own setup.

DO NOT register your controllers, plugins or anything that might want to use config() in here, do that in init()

Member Function Documentation

void Cutelyst::Application::addTranslator ( const QLocale &  locale,
QTranslator *  translator 

Adds a translator for the specified locale.

You can add multiple translators for different application parts for every supported locale. The installed translators will then be used by Context::translate() (what itself will use Application::translate()) to translate strings according to the locale set by Context::setLocale().

Usage example:
bool MyCutelystApp::init()
// ...
auto trans = new QTranslator(this);
QLocale deDE(QLocale::German, QLocale::Germany);
if (trans->load(deDE, QStringLiteral("mycutelystapp"), QStringLiteral("."), QStringLiteral("/usr/share/mycutelystapp/l10n")) {
addTranslator(deDE, trans);
// ...
Cutelyst 1.5.0
void Cutelyst::Application::addTranslator ( const QString &  locale,
QTranslator *  translator 

Adds a translator for the specified locale.

The locale string has to be parseable by QLocale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Cutelyst 1.5.0
void Cutelyst::Application::addTranslators ( const QLocale &  locale,
const QVector< QTranslator * > &  translators 

Adds multiple translators for the specified locale.

See also
Cutelyst 1.5.0
void Cutelyst::Application::afterDispatch ( Context c)

This signal is emitted right after the Action found by the dispatcher got executed.

void Cutelyst::Application::beforeDispatch ( Context c)

This signal is emitted right after the Dispatcher returns the Action that will be executed.

void Cutelyst::Application::beforePrepareAction ( Context c,
bool *  skipMethod 

This signal is emitted before the Dispatcher is called to find an action. It's useful if you need to intercept requests before they are dispached. Always check skipMethod and return if it's true. In case you want to stop further processing set skipMethod to true.

QVariant Cutelyst::Application::config ( const QString &  key,
const QVariant &  defaultValue = QVariant() 
) const

Returns application config specified by key, with a possible default value.

QVariantMap Cutelyst::Application::config ( ) const

User configuration for the application

A variant hash with configuration settings
QVector<Controller *> Cutelyst::Application::controllers ( ) const

Returns a list with all registered controllers.

The list might only be complete after application has been setup.

Component* Cutelyst::Application::createComponentPlugin ( const QString &  name,
QObject *  parent = nullptr 

Tries to load a plugin in Cutelyst default plugin directory with parent as it's parent. A nullptr is returned in case of failure.

static const char* Cutelyst::Application::cutelystVersion ( )

Returns cutelyst version.

Headers& Cutelyst::Application::defaultHeaders ( )

This is the HTTP default response headers that each request gets

Do not change it after the application has started.

Dispatcher* Cutelyst::Application::dispatcher ( ) const

Returns the dispatcher class.

QVector<DispatchType *> Cutelyst::Application::dispatchers ( ) const

Returns a list with all registered dispachers.

The list might only be complete after application has been setup.

Engine* Cutelyst::Application::engine ( ) const

Returns current engine that is generating requests.

virtual bool Cutelyst::Application::init ( )

Do your application initialization here, if your application should not proceed log some information that might help on debuggin and return false

For example if your application only works with PostgeSQL and the Qt driver is not available it makes sense to fail here. However you should not initialize resouces that cannot be shared among process.

See also
true if your application was successfuly initted
bool Cutelyst::Application::inited ( ) const

Returns true if the application has been inited.

QString Cutelyst::Application::pathTo ( const QString &  path) const

Merges path with config("HOME") and returns an absolute path.

QString Cutelyst::Application::pathTo ( const QStringList &  path) const

Merges path with config("HOME") and returns an absolute path.

QVector<Plugin *> Cutelyst::Application::plugins ( ) const

Returns all registered plugins

virtual bool Cutelyst::Application::postFork ( )

This method is called after the engine forks

After the web engine forks itself it will call this function so that you can initialize resources that can't be shared with the parent process, namely sockets and file descriptors.

A good example of usage of this function is when openning a connection to the database which can't be shared with other process and should probably make this function return false if it fails to open.

Default implementation returns true.

False if the engine should not use this process
void Cutelyst::Application::postForked ( Application app)

This signal is emitted after before

See also
postFork() is called.
void Cutelyst::Application::preForked ( Application app)

This signal is emitted right after application has been setup and before application forks and

See also
postFork() is called.
bool Cutelyst::Application::registerController ( Controller controller)

This method registers a Controller class which is responsible for handlying Requests, since they are reused between multiple requests beaware of not storing data there, instead you might want to use a session plugin or the stash.

controllerthe Controller class
true if succeeded
bool Cutelyst::Application::registerDispatcher ( DispatchType dispatcher)

Registers a custom DispatchType, if none is registered all the built-in dispatchers types will be registered

bool Cutelyst::Application::registerPlugin ( Plugin plugin)

Registers a global plugin ie one that doesn't need to be created explicity for a single request and returns true on plugin->isApplicationPlugin();

true if the plugin could be registered
bool Cutelyst::Application::registerView ( View view)

This method registers a View class which is responsible for rendering requests.

viewthe View class
true if succeeded
void Cutelyst::Application::setConfig ( const QString &  key,
const QVariant &  value 

Change the value of the configuration key You should never call this from random parts of the code as a way to store shareable data, it should only be called by a subclass

QString Cutelyst::Application::translate ( const QLocale &  locale,
const char *  context,
const char *  sourceText,
const char *  disambiguation = nullptr,
int  n = -1 
) const

Translates the sourceText into the target locale language.

This uses the installed translators for the specified locale to translate the sourceText for the given context into the target locale. Optionally you can use a disambiguation and/or the n parameter to translate a pluralized version.

See also
Context::translate(), QTranslator::translate()
Cutelyst 1.5.0
View* Cutelyst::Application::view ( const QString &  name = QString()) const

Returns the view specified by name, if no view is found nullptr is returned.