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
access-singleton-via-object.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qmllint-warnings-and-errors-access-singleton-via-object.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Cannot access singleton as a property of an object
9
\brief [access-singleton-via-object] A singleton was incorrectly accessed.
10
11
\qmllintwarningcategory access-singleton-via-object
12
13
\section1 Access singleton via object
14
15
\section2 What happened?
16
You accessed a singleton using the syntax for accessing attached properties
17
from a namespace.
18
19
\section2 Why is this bad?
20
Singletons can't be accessed in this way. The expression will evaluate to undefined.
21
22
\section2 Example
23
\qml
24
import QtQml
25
import QtQuick as QQ
26
27
QtObject {
28
id: root
29
// Cannot access singleton as a property of an object. Did you want to access an attached object?
30
property var singletonAccess: root.QQ.Application.platform
31
}
32
\endqml
33
34
To fix this warning, remove the \c{id} or property in front of the namespace if
35
you intended to use the singleton. Alternatively, check for typos if you wanted
36
to access an attached property.
37
38
\qml
39
import QtQml
40
import QtQuick as QQ
41
42
QtObject {
43
id: root
44
property var singletonAccess: QQ.Application.platform
45
property bool attachedPropertyAccess: root.QQ.ListView.isCurrentItem
46
}
47
\endqml
48
*/
qtdeclarative
src
qml
doc
src
qmllint
access-singleton-via-object.qdoc
Generated on
for Qt by
1.14.0