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