Qt
6.x
The Qt SDK
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
5
class
MySingleton
:
public
QObject
{
6
Q_OBJECT
7
8
// Register as default constructed singleton.
9
QML_ELEMENT
10
QML_SINGLETON
11
12
static
int
typeId;
13
// ...
14
};
16
17
/*
19
MySingleton::typeId = qmlTypeId(...);
21
*/
22
23
void
wrapper2
() {
25
// Retrieve as QObject*
26
QQmlEngine
engine
;
27
MySingleton
* instance =
engine
.singletonInstance<
MySingleton
*>(MySingleton::typeId);
29
}
30
31
/*
33
// Register with QJSValue callback
34
int typeId = qmlRegisterSingletonType(...);
36
*/
37
38
void
wrapper4
(
int
typeId) {
40
// Retrieve as QJSValue
41
QQmlEngine
engine
;
42
QJSValue
instance =
engine
.singletonInstance<
QJSValue
>(typeId);
44
}
45
46
void
wrapper5
() {
48
QQmlEngine
engine
;
49
MySingleton
*singleton =
engine
.singletonInstance<
MySingleton
*>(
"mymodule"
,
"MySingleton"
);
51
}
MySingleton
[0]
Definition
src_qml_qqmlengine.cpp:5
QJSValue
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition
qjsvalue.h:31
QObject
\inmodule QtCore
Definition
qobject.h:90
QQmlEngine
The QQmlEngine class provides an environment for instantiating QML components.
Definition
qqmlengine.h:57
QML_SINGLETON
#define QML_SINGLETON
Definition
qqmlintegration.h:75
QML_ELEMENT
#define QML_ELEMENT
Definition
qqmlintegration.h:41
Q_OBJECT
#define Q_OBJECT
Definition
qtmetamacros.h:117
wrapper2
void wrapper2()
[0]
Definition
src_qml_qqmlengine.cpp:23
wrapper5
void wrapper5()
Definition
src_qml_qqmlengine.cpp:46
wrapper4
void wrapper4(int typeId)
Definition
src_qml_qqmlengine.cpp:38
engine
QJSEngine engine
[0]
Definition
src_script_qjsvalue.cpp:14
qtdeclarative
src
qml
doc
snippets
code
src_qml_qqmlengine.cpp
Generated by
1.9.7