-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.0.0, 5.15.3, 6.10.0 FF, 6.12
-
None
-
ed607c86a (dev), 600cb8d8d (6.10)
In QQuick gradient, The QQuickGradientStop class does not initialize m_position to 0.0 that the dcoumentation claims to.
/*! \qmlproperty real QtQuick::GradientStop::position \qmlproperty color QtQuick::GradientStop::color The position and color properties describe the color used at a given position in a gradient, as represented by a gradient stop. The default position is 0.0; the default color is black. \sa Gradient*/ QQuickGradientStop::QQuickGradientStop(QObject *parent) : QObject(parent) { }
While most users do provide the position for each GradientStop, it is possible to forget about it. As a result, an uninitialized value is used, which can cause undefined behavior to CPU/GPU.
I added a log in where the gradient is used.
Rectangle {
....
gradient: Gradient {
GradientStop {
color: xxxxx
}
GradientStop {
position: 1
color: xxxxx
}
}
Component.onCompleted: { console.log("Gradientstop 0 position: ", gradient.stops[0].position); }
}
and here is the log
2025-09-18_16:20:27.83803 qml: Gradientstop 0 position: 0 2025-09-18_16:20:27.83854 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.32487 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.32517 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.32861 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.32976 qml: Gradientstop 0 position: 2.2420775429197073e-43 2025-09-18_16:20:29.33046 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.33066 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.33114 qml: Gradientstop 0 position: 0 2025-09-18_16:20:29.33136 qml: Gradientstop 0 position: 5.75528247281909e-8 2025-09-18_16:21:33.83072 qml: Gradientstop 0 position: NaN
Clearly, random value is picked up on each time the gradient is created. I have checked that such bug exists on every version of Qt for as long rectangle gradient was available
Fix:
QQuickGradientStop::QQuickGradientStop(QObject *parent) : QObject(parent), m_position(0.0) { }