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