KDeclarative::KDeclarative

Search for usage in LXR

KDeclarative::KDeclarative Class Reference

#include <KDeclarative/KDeclarative>

Public Member Functions

 KDeclarative (const KDeclarative &)=delete
 
QQmlEnginedeclarativeEngine () const
 
void initialize ()
 
KDeclarativeoperator= (const KDeclarative &)=delete
 
void setDeclarativeEngine (QQmlEngine *engine)
 
void setTranslationDomain (const QString &translationDomain)
 
void setupBindings ()
 
void setupContext ()
 
QString translationDomain () const
 

Static Public Member Functions

static QString componentsTarget ()
 
static QString defaultComponentsTarget ()
 
static QStringList runtimePlatform ()
 
static void setRuntimePlatform (const QStringList &platform)
 
static void setupEngine (QQmlEngine *engine)
 
static void setupQmlJsDebugger ()
 

Detailed Description

The KDeclarative class is used to manipulate the QQmlEngine instance used by the application and to get some information about the platform, that influences the behavior of the QML components.

In order to use it, you will need a pointer to a QQmlEngine, and call setupEngine(engine) at least once on the engine.

KDeclarative::KDeclarative::setupEngine(engine); // if not done elsewhere

To setup integration with KI18n's translation methods and thus being able to call i18n() from anywhere in your QML code., you set a KLocalizedContext from Ki18n directly like this (since KF 5.17):

KLocalizedContext *localizedContextObject = new KLocalizedContext(engine);
// if not using the global application domain, set custom domain name
localizedContextObject->setTranslationDomain(QStringLiteral("mydomainname"));
engine->rootContext()->setContextObject(localizedContextObject);

In case your code should work with KF versions before 5.17, use these deprecated calls instead:

decl.setDeclarativeEngine(engine);
// if not using the global application domain, set custom domain name
decl.setTranslationDomain(QStringLiteral("mydomainname"));
decl.setupContext();

Definition at line 56 of file kdeclarative.h.

Member Function Documentation

◆ componentsTarget()

QString KDeclarative::KDeclarative::componentsTarget ( )
static
Returns
the QML components target, based on the runtime platform. e.g. touch or desktop
Since
4.10

Definition at line 155 of file kdeclarative.cpp.

◆ declarativeEngine()

QQmlEngine * KDeclarative::KDeclarative::declarativeEngine ( ) const
Returns
the engine assigned to this KDeclarative. The engine may be a nullptr . No ownership is transferred.
See also
setDeclarativeEngine(), setupEngine()
Since
5.0

Definition at line 51 of file kdeclarative.cpp.

◆ defaultComponentsTarget()

QString KDeclarative::KDeclarative::defaultComponentsTarget ( )
static
Returns
the default components target; can be used to compare against the returned value from
See also
componentsTarget()
Since
4.10

Definition at line 150 of file kdeclarative.cpp.

◆ initialize()

void KDeclarative::KDeclarative::initialize ( )
Deprecated:
since 5.0.

The method is a no-op now, any call can be simply removed.

Definition at line 57 of file kdeclarative.cpp.

◆ runtimePlatform()

QStringList KDeclarative::KDeclarative::runtimePlatform ( )
static
Returns
the runtime platform, e.g. "desktop" or "tablet, touch". The first entry/ies in the list relate to the platform formfactor and the last is the input method specialization. If the string is empty, there is no specified runtime platform and a traditional desktop environment may be assumed
Since
4.10

Definition at line 165 of file kdeclarative.cpp.

◆ setDeclarativeEngine()

void KDeclarative::KDeclarative::setDeclarativeEngine ( QQmlEngine engine)

Assign a specific QQmlEngine to be used in this KDeclarative.

A KDeclarative object works with a specific QQmlEngine. There is no default engine, so you must call this function with a non-null pointer to an engine before calling setupBindings() or setupContext(), which set properties on the engine.

The KDeclarative object does not take ownership of the engine.

Parameters
enginethe engine to use in this KDeclarative object
See also
setupContext(), setupEngine()
Since
5.0

Definition at line 43 of file kdeclarative.cpp.

◆ setRuntimePlatform()

void KDeclarative::KDeclarative::setRuntimePlatform ( const QStringList platform)
static

Sets the runtime platform from now on, globally to the process.

Already loaded QML components won't be affected.

Since
5.0

Definition at line 179 of file kdeclarative.cpp.

◆ setTranslationDomain()

void KDeclarative::KDeclarative::setTranslationDomain ( const QString translationDomain)

Call this method before calling setupContext to install a translation domain for all i18n global functions.

If a translation domain is set all i18n calls delegate to the matching i18nd calls with the provided translation domain.

The translationDomain affects all i18n calls including those from imports. Because of that modules intended to be used as imports should prefer the i18nd variants and set the translation domain explicitly in each call.

This method is only required if your declarative usage is inside a library. If it's in an application there is no need to set the translation domain as the application's domain can be used.

Parameters
translationDomainThe translation domain to be used for i18n calls.
Since
5.0
Deprecated:
Since 5.17 use KLocalizedContext::setTranslationDomain

Definition at line 125 of file kdeclarative.cpp.

◆ setupBindings()

void KDeclarative::KDeclarative::setupBindings ( )

Call this after setDeclarativeEngine to set the i18n global functions, the runtime platform, etc.

Deprecated:
since 5.45 use setupContext() and setupEngine()

Definition at line 63 of file kdeclarative.cpp.

◆ setupContext()

void KDeclarative::KDeclarative::setupContext ( )

Call this after setDeclarativeEngine to set the i18n global functions.

See also
setupEngine
Since
5.45
Deprecated:
Since 5.17 set KLocalizedContext directly, see documentation in KI18n::KLocalizedContext

Definition at line 71 of file kdeclarative.cpp.

◆ setupEngine()

void KDeclarative::KDeclarative::setupEngine ( QQmlEngine engine)
static

Setup a QML engine for use with any KDeclarative object.

This needs to be done only once per QQmlEngine instance. An engine that is shared between KDeclarative objects only needs to be setup once. The engine is setup for the component target (runtime platform) that is configured at the time setupEngine() is called. The following things are added to the engine:

  • a KIOAccessManagerFactory, replacing any existing stock QQmlNetworkAccessManagerFactory
  • a QML icon provider, enabling the Image {} element to load images using the scheme "image:/"
Parameters
enginethe engine to setup
See also
setupContext(), componentsTarget()
Since
5.45

Definition at line 92 of file kdeclarative.cpp.

◆ setupQmlJsDebugger()

void KDeclarative::KDeclarative::setupQmlJsDebugger ( )
static

This method must be called very early at startup time to ensure the QQuickDebugger is enabled.

Ideally it should be called in main(), after command-line options are defined.

Since
5.0

Definition at line 141 of file kdeclarative.cpp.

◆ translationDomain()

QString KDeclarative::KDeclarative::translationDomain ( ) const
Returns
the translation domain for the i18n calls done in this QML engine
Since
5.0
Deprecated:
Since 5.17 use KLocalizedContext::translationDomain

Definition at line 135 of file kdeclarative.cpp.


The documentation for this class was generated from the following files:
void setDeclarativeEngine(QQmlEngine *engine)
Assign a specific QQmlEngine to be used in this KDeclarative.
void setTranslationDomain(const QString &translationDomain)
Call this method before calling setupContext to install a translation domain for all i18n global func...
static void setupEngine(QQmlEngine *engine)
Setup a QML engine for use with any KDeclarative object.
void setupContext()
Call this after setDeclarativeEngine to set the i18n global functions.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed May 25 2022 04:03:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.