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]
5class MySingleton : public QObject {
6 Q_OBJECT
7
8 // Register as default constructed singleton.
9 QML_ELEMENT
11
12 static int typeId;
13 // ...
14};
15//! [0]
16
17/*
18//! [1]
19 MySingleton::typeId = qmlTypeId(...);
20//! [1]
21*/
22
23void 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
38void wrapper4(int typeId) {
39//! [4]
40 // Retrieve as QJSValue
41 QQmlEngine engine;
42 QJSValue instance = engine.singletonInstance<QJSValue>(typeId);
43//! [4]
44}
45
46void wrapper5() {
47//! [5]
48 QQmlEngine engine;
49 MySingleton *singleton = engine.singletonInstance<MySingleton *>("mymodule", "MySingleton");
50//! [5]
51}
void wrapper2()
[0]
void wrapper5()
void wrapper4(int typeId)