Issue with Array.IsArray in Qt6.5
-
I am working on migrating an application from Qt 5.15 to Qt 6.5, but I am running into an issue with Array.IsArray. This works in Qt 5.15, but I always get false as a result in Qt 6.5. The following code is placed in a delegate.
console.log(Array.isArray(switchbox.switches) + " " + Object.prototype.toString.call(switchbox.switches)) console.log(switchbox.switches.toString() )
This gives the following output in Qt5:
2024-12-11 14:24:29:374 [tango/qml/runMode/WidgetSwitchbox_01.qml::68] true [object Array] 2024-12-11 14:24:29:374 [tango/qml/runMode/WidgetSwitchbox_01.qml::70] 2,2,2,2,2,2
But on Qt6.5 I get this:
2024-12-11 14:22:24:635 [tango/qml/runMode/WidgetSwitchbox_01.qml::67] false [object V4Sequence] 2024-12-11 14:22:24:635 [tango/qml/runMode/WidgetSwitchbox_01.qml::69] 2,2,2,2,2,2
Has something changed in the functionality of IsArray? And what is a V4Sequence?
-
Hello Johan, could you share what switchbox actually is (QML component or C++?) and how its property "switches" is defined?
-
It is quite a way to get to the real data.
Within the delegate switchbox is defined as:property var switchbox: model.modelData
The model is filled in a function inside the listview:
function filter() { var newModel = [] for (var i = 0; i < switchboxList.length; i++) { if (switchboxList[i].enabled) { newModel.push(switchboxList[i]) } } model = newModel }
switchboxList is recevied from c++:
property var switchboxList: ipc.iface.switchboxes
And switchboxes is a Q_PROPERTY defined as QList<QObject*>.
-
The consensus seems to not have to rely on
Array.isArray
: https://bugreports.qt.io/browse/QTBUG-125289