Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
4
//! [0]
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
};
15
//! [0]
16
17
/*
18
//! [1]
19
MySingleton::typeId = qmlTypeId(...);
20
//! [1]
21
*/
22
23
void
wrapper2
() {
24
//! [2]
25
// Retrieve as QObject*
26
QQmlEngine engine;
27
MySingleton
* instance = engine.singletonInstance<MySingleton*>(MySingleton::typeId);
28
//! [2]
29
}
30
31
/*
32
//! [3]
33
// Register with QJSValue callback
34
int typeId = qmlRegisterSingletonType(...);
35
//! [3]
36
*/
37
38
void
wrapper4
(
int
typeId) {
39
//! [4]
40
// Retrieve as QJSValue
41
QQmlEngine engine;
42
QJSValue instance = engine.singletonInstance<QJSValue>(typeId);
43
//! [4]
44
}
45
46
void
wrapper5
() {
47
//! [5]
48
QQmlEngine engine;
49
MySingleton
*singleton = engine.singletonInstance<
MySingleton
*>(
"mymodule"
,
"MySingleton"
);
50
//! [5]
51
}
MySingleton
[0]
Definition
src_qml_qqmlengine.cpp:5
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
qtdeclarative
src
qml
doc
snippets
code
src_qml_qqmlengine.cpp
Generated on
for Qt by
1.14.0