PlasmaQuick::SharedQmlEngine Class
class PlasmaQuick::SharedQmlEngineHeader: | #include <SharedQmlEngine> |
CMake: | find_package(PlasmaQuick REQUIRED) target_link_libraries(mytarget PRIVATE Plasma::PlasmaQuick) |
Inherits: | QObject |
Public Functions
SharedQmlEngine(QObject *parent = nullptr) | |
QObject * | createObjectFromComponent(QQmlComponent *component, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash()) |
QObject * | createObjectFromSource(const QUrl &source, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash()) |
std::shared_ptr<QQmlEngine> | engine() |
bool | isInitializationDelayed() const |
QQmlComponent * | mainComponent() const |
QQmlContext * | rootContext() const |
QObject * | rootObject() const |
void | setInitializationDelayed(const bool delay) |
void | setSource(const QUrl &source) |
void | setSourceFromModule(QAnyStringView module, QAnyStringView type) |
void | setTranslationDomain(const QString &translationDomain) |
QUrl | source() const |
QQmlComponent::Status | status() const |
QString | translationDomain() const |
Public Slots
void | completeInitialization(const QVariantHash &initialProperties = QVariantHash()) |
Signals
void | finished() |
void | statusChanged(QQmlComponent::Status) |
Detailed Description
@short An object that instantiates an entire QML context, with its own declarative engine
PlasmaQuick::SharedQmlEngine provides a class to conveniently use QML based declarative user interfaces. A SharedQmlEngine corresponds to one QML file (which can include others). It will a shared QQmlEngine with a single root object, described in the QML file.
@since 6.0
Member Function Documentation
[explicit]
SharedQmlEngine::SharedQmlEngine(QObject *parent = nullptr)
Construct a new PlasmaQuick::SharedQmlEngine
@param parent The QObject parent for this object.
[slot]
void SharedQmlEngine::completeInitialization(const QVariantHash &initialProperties = QVariantHash())
Finishes the process of initialization. If isInitializationDelayed() is false, calling this will have no effect. @param initialProperties optional properties that will be set on the object when created (and before Component.onCompleted gets emitted
QObject *SharedQmlEngine::createObjectFromComponent(QQmlComponent *component, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash())
Creates and returns an object based on the provided QQmlComponent with the same QQmlEngine and the same root context as the admin object, that will be the parent of the newly created object @param component the component we want to instantiate @param context The QQmlContext in which we will create the object, if 0 it will use the engine's root context @param initialProperties optional properties that will be set on the object when created (and before Component.onCompleted gets emitted
QObject *SharedQmlEngine::createObjectFromSource(const QUrl &source, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash())
Creates and returns an object based on the provided url to a Qml file with the same QQmlEngine and the same root context as the main object, that will be the parent of the newly created object @param source url where the QML file is located @param context The QQmlContext in which we will create the object, if 0 it will use the engine's root context @param initialProperties optional properties that will be set on the object when created (and before Component.onCompleted gets emitted
std::shared_ptr<QQmlEngine> SharedQmlEngine::engine()
@return the declarative engine that runs the qml file assigned to this widget.
[signal]
void SharedQmlEngine::finished()
Emitted when the parsing and execution of the QML file is terminated
bool SharedQmlEngine::isInitializationDelayed() const
@return true if the initialization of the QML file will be delayed at the end of the event loop
Note: Getter function for property initializationDelayed.
QQmlComponent *SharedQmlEngine::mainComponent() const
@return the main QQmlComponent of the engine
QQmlContext *SharedQmlEngine::rootContext() const
The components's creation context.
QObject *SharedQmlEngine::rootObject() const
@return the root object of the declarative object tree
Note: Getter function for property rootObject.
void SharedQmlEngine::setInitializationDelayed(const bool delay)
Sets whether the execution of the QML file has to be delayed later in the event loop. It has to be called before setQmlPath(). In this case it will be possible to assign new objects in the main engine context before the main component gets initialized. In that case it will be possible to access it immediately from the QML code. The initialization will either be completed automatically asynchronously or explicitly by calling completeInitialization()
@param delay if true the initialization of the QML file will be delayed at the end of the event loop
Note: Setter function for property initializationDelayed.
See also isInitializationDelayed().
void SharedQmlEngine::setSource(const QUrl &source)
Sets the path of the QML file to parse and execute
@param path the absolute path of a QML file
Note: Setter function for property source.
See also source().
void SharedQmlEngine::setSourceFromModule(QAnyStringView module, QAnyStringView type)
Sets the QML source to execute from a type in a module.
@param module The module to load the type from. @param type The type to load from the module.
void SharedQmlEngine::setTranslationDomain(const QString &translationDomain)
Call this method before calling setupBindings 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.
@param translationDomain The translation domain to be used for i18n calls.
Note: Setter function for property translationDomain.
See also translationDomain().
QUrl SharedQmlEngine::source() const
@return the absolute path of the current QML file
Note: Getter function for property source.
See also setSource().
QQmlComponent::Status SharedQmlEngine::status() const
The component's current status.
Note: Getter function for property status.
QString SharedQmlEngine::translationDomain() const
@return the translation domain for the i18n calls done in this QML engine
Note: Getter function for property translationDomain.
See also setTranslationDomain().