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