Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_qml_qqmlengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5class MySingleton : public QObject {
7
8 // Register as default constructed singleton.
11
12 static int typeId;
13 // ...
14};
16
17/*
19 MySingleton::typeId = qmlTypeId(...);
21*/
22
23void wrapper2() {
25 // Retrieve as QObject*
27 MySingleton* instance = engine.singletonInstance<MySingleton*>(MySingleton::typeId);
29}
30
31/*
33 // Register with QJSValue callback
34 int typeId = qmlRegisterSingletonType(...);
36*/
37
38void wrapper4(int typeId) {
40 // Retrieve as QJSValue
42 QJSValue instance = engine.singletonInstance<QJSValue>(typeId);
44}
45
46void wrapper5() {
49 MySingleton *singleton = engine.singletonInstance<MySingleton *>("mymodule", "MySingleton");
51}
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qobject.h:103
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
#define QML_SINGLETON
#define QML_ELEMENT
#define Q_OBJECT
void wrapper2()
[0]
void wrapper5()
void wrapper4(int typeId)
QJSEngine engine
[0]