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?
15You accessed a singleton using the syntax for accessing attached properties
16from a namespace.
17
18\section2 Why is this bad?
19Singletons can't be accessed in this way. The expression will evaluate to undefined.
20
21\section2 Example
22\qml
23import QtQml
24import QtQuick as QQ
25
26QtObject {
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
33To fix this warning, remove the \c{id} or property in front of the namespace if
34you intended to use the singleton. Alternatively, check for typos if you wanted
35to access an attached property.
36
37\qml
38import QtQml
39import QtQuick as QQ
40
41QtObject {
42 id: root
43 property var singletonAccess: QQ.Application.platform
44 property bool attachedPropertyAccess: root.QQ.ListView.isCurrentItem
45}
46\endqml
47*/