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
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
12// Singleton.h
13class Singleton : public QObject
14{
16 Q_PROPERTY(int thing READ thing WRITE setThing NOTIFY thingChanged FINAL)
19
20public:
22
23 int thing() const { return m_value; }
24 void setThing(int v)
25 {
26 if (v != m_value) {
27 m_value = v;
29 }
30 }
31
34
35private:
36 int m_value = 12;
37};
39
41{
43 Singleton *singleton
44 = engine->singletonInstance<Singleton *>("MyModule", "Singleton");
45 singleton->setThing(77);
47}
48
49#endif
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void thingChanged()
int thing
Definition singleton.h:16
void setThing(int v)
Definition singleton.h:24
int thing() const
Definition singleton.h:23
Singleton(QObject *parent=nullptr)
Definition singleton.h:21
GLsizei const GLfloat * v
[13]
#define QML_SINGLETON
#define QML_ELEMENT
#define Q_PROPERTY(...)
#define Q_OBJECT
#define signals
#define emit
void setTheThing(QQmlEngine *engine)
[0]
Definition singleton.h:40
QJSEngine engine
[0]