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
incompatible-type.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 Incompatible type
8
\brief [incompatible-type] An object, value, or expression is used on an incompatible type.
9
10
\qmllintwarningcategory incompatible-type
11
12
\section1 Cannot assign to default property of incompatible type
13
14
\section2 What happened?
15
You assigned an object to a
16
\l{qtqml-syntax-objectattributes.html#default-properties}{default property}
17
of an incompatible type.
18
19
\section2 Why is this bad?
20
The QML engine will not be able to assign the object at runtime.
21
22
\section2 Example
23
\qml
24
import QtQuick
25
26
Item {
27
component MyType: QtObject {
28
default property list<Item> myDefaultProperty
29
}
30
31
MyType {
32
QtObject {} // note: QtObject does not inherit from Item
33
}
34
}
35
36
\endqml
37
To fix this warning, bind a compatible type to the property or, if
38
you are the author of the default property, change the type in
39
the definition:
40
\qml
41
import QtQuick
42
43
Item {
44
component MyType: QtObject {
45
default property list<Item> myDefaultProperty
46
}
47
48
MyType {
49
Item {}
50
}
51
52
component AlternativeMyType: QtObject {
53
default property list<QtObject> myDefaultProperty
54
}
55
56
AlternativeMyType {
57
QtObject {} // is ok for AlternativeMyType
58
}
59
}
60
61
\endqml
62
63
\section1 On-binding for property has wrong type
64
65
\section2 What happened?
66
You used an invalid
67
\l{qtqml-cppintegration-definetypes.html#property-modifier-types}{property modifier type}.
68
69
\section2 Why is this bad?
70
The QML engine will not be able to use the property modifier type at runtime.
71
72
\section2 Example
73
\qml
74
import QtQuick
75
76
Item {
77
property int xxx
78
Item on xxx { ... }
79
}
80
81
\endqml
82
To fix this warning, remove the \c on or use a valid
83
\l{qtqml-cppintegration-definetypes.html#property-modifier-types}{property modifier type}:
84
\qml
85
import QtQuick
86
87
Item {
88
property int xxx
89
Item { ... }
90
91
// Alternative: use a valid property modifier type
92
NumberAnimation on xxx { ... }
93
}
94
95
\endqml
96
97
\section1 Construction from string is deprecated; Use structured value type construction instead
98
99
\section2 What happened?
100
You constructed a QML_STRUCTURED_VALUE using a string.
101
102
\section2 Why is this bad?
103
This is deprecated and prone to typos.
104
105
\section2 Example
106
\qml
107
import QtQuick
108
109
Item {
110
property point p: "5, 6"
111
}
112
113
\endqml
114
To fix this warning, populate the structured value type as explained in the
115
QML_STRUCTURED_VALUE description instead of binding a string to the property:
116
117
\qml
118
import QtQuick
119
120
Item {
121
property point p: ({ x: 5, y: 6 })
122
}
123
124
\endqml
125
126
\section1 Function without return type annotation returns
127
128
\section2 What happened?
129
You returned a value from a function without return type annotation.
130
131
\section2 Why is this bad?
132
You annotated the function to not return anything so the function should not return anything.
133
The QML tooling will not be able to process the method and the QML engine will ignore the
134
returned value in a future Qt version.
135
136
\section2 Example
137
\qml
138
import QtQuick
139
140
Item {
141
function f(x: int) {
142
...
143
return x
144
}
145
}
146
147
\endqml
148
To fix this warning, adapt the function signature to the new return type or remove the return value:
149
\qml
150
import QtQuick
151
152
Item {
153
function f(x: int): int {
154
...
155
return x
156
}
157
function alternativeF(x: int) {
158
...
159
return
160
}
161
}
162
163
\endqml
164
165
\section1 Cannot assign binding/object/literal
166
167
\section2 What happened?
168
You bound an object, literal, or expression to a property of an incompatible type.
169
170
\section2 Why is this bad?
171
The QML engine will not be able to assign the object, literal, or expression at runtime.
172
173
\section2 Example
174
\qml
175
import QtQuick
176
177
Item {
178
property date xxx: 42
179
}
180
181
\endqml
182
To fix this warning, bind an object, value, or expression of a compatible type:
183
\qml
184
import QtQuick
185
186
Item {
187
property date xxx: new Date()
188
}
189
190
\endqml
191
192
*/
qtdeclarative
src
qml
doc
src
qmllint
incompatible-type.qdoc
Generated on
for Qt by
1.16.1