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
singleton.h
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
ifndef
SINGLETON_H
5
#
define
SINGLETON_H
6
7
#
include
<
QtQml
/
qobject
.
h
>
8
#
include
<
QtQml
/
qqml
.
h
>
9
#
include
<
QtQml
/
qqmlengine
.
h
>
10
11
//![0]
12
// Singleton.h
13
class
Singleton
:
public
QObject
14
{
15
Q_OBJECT
16
Q_PROPERTY(
int
thing READ thing WRITE setThing NOTIFY thingChanged FINAL)
17
QML_ELEMENT
18
QML_SINGLETON
19
20
public
:
21
Singleton
(
QObject
*
parent
=
nullptr
) :
QObject
(
parent
) {}
22
23
int
thing
()
const
{
return
m_value
; }
24
void
setThing
(
int
v
)
25
{
26
if
(
v
!=
m_value
) {
27
m_value
=
v
;
28
emit
thingChanged
();
29
}
30
}
31
32
signals
:
33
void
thingChanged
();
34
35
private
:
36
int
m_value = 12;
37
};
38
//![0]
39
40
inline
void
setTheThing
(QQmlEngine *engine)
41
{
42
//![1]
43
Singleton
*singleton
44
= engine->singletonInstance<
Singleton
*>(
"MyModule"
,
"Singleton"
);
45
singleton->setThing(77);
46
//![1]
47
}
48
49
#
endif
Singleton::Singleton
Singleton(QObject *parent=nullptr)
Definition
singleton.h:21
setTheThing
void setTheThing(QQmlEngine *engine)
[0]
Definition
singleton.h:40
qtdeclarative
src
qml
doc
snippets
qml
exposing-state
singleton.h
Generated on
for Qt by
1.14.0