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
signal-handler-name-clash.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 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 Signal handler name clash
8
\brief [signal-handler-name-clash] A property name is also a signal handler name.
9
10
\qmllintwarningcategory signal-handler-name-clash
11
12
\section1 Property is interpreted as a signal handler
13
14
\section2 What happened?
15
You declared a property whose name follows the \c{on<Signal>} pattern QML uses for signal
16
handlers, and the object also has a member the handler could belong to: either a signal
17
\c{<signal>} from the type itself or one of its base types, or a property \c{<signal>}
18
declared in the same object.
19
20
\section2 Why is this bad?
21
The signal handler interpretation wins. Any binding to such a property, including the
22
property's own initializer, is compiled as a signal handler rather than as a property
23
binding. A literal initializer makes the component fail to load with
24
\c{Cannot assign a value to a signal (expecting a script to be run)}, and an expression
25
initializer is silently run as a signal handler, leaving the property at its default value.
26
27
\section2 Example
28
\qml
29
import QtQuick
30
31
Item {
32
property color primary: "green"
33
property color onPrimary: "white" // not ok: read as a handler for "primary"
34
35
signal accepted()
36
property bool onAccepted: false // not ok: read as a handler for the "accepted" signal
37
}
38
\endqml
39
To fix this warning, rename the properties so that they do not start with \c on followed by an
40
upper-case letter:
41
\qml
42
import QtQuick
43
44
Item {
45
property color primary: "green"
46
property color textOnPrimary: "white"
47
48
signal accepted()
49
property bool acceptedState: false
50
}
51
\endqml
52
*/
qtdeclarative
src
qml
doc
src
qmllint
signal-handler-name-clash.qdoc
Generated on
for Qt by
1.16.1