[QObjectList] Cannot read property 'forEach' of null in javascript
-
wrote on 4 Feb 2019, 23:30 last edited by
Hi,
I got "Cannot read property 'forEach' of null" error message from javascript when I try to list of QObjectList using forEach.Do you know how to enumerate the list of QObject from QObjectList in javascript?
Looks like "forEach" is not supported.
Thank you.
-
A standard loop should work fine:
for (var i = 0; i < list.length; ++i) { console.log(list[i]) }
Also, try Qt 5.12.1, JS support was improved there, perhaps forEach would work.
-
Hi,
I got "Cannot read property 'forEach' of null" error message from javascript when I try to list of QObjectList using forEach.Do you know how to enumerate the list of QObject from QObjectList in javascript?
Looks like "forEach" is not supported.
Thank you.
wrote on 5 Feb 2019, 09:37 last edited by@zosskr said in [QObjectList] Cannot read property 'forEach' of null in javascript:
Cannot read property 'forEach' of null" error message
That implies in any case that your
QObjectList
variable isnull
, so you need to check that first.... -
A standard loop should work fine:
for (var i = 0; i < list.length; ++i) { console.log(list[i]) }
Also, try Qt 5.12.1, JS support was improved there, perhaps forEach would work.
-
@zosskr said in [QObjectList] Cannot read property 'forEach' of null in javascript:
Cannot read property 'forEach' of null" error message
That implies in any case that your
QObjectList
variable isnull
, so you need to check that first.... -
A standard loop should work fine:
for (var i = 0; i < list.length; ++i) { console.log(list[i]) }
Also, try Qt 5.12.1, JS support was improved there, perhaps forEach would work.
-
@JonB : Thank you for the answer. I already verified the object is valid. I think QObjectList is not supported in 5.12.0 for JS. may need to check with higher version.
@zosskr said in [QObjectList] Cannot read property 'forEach' of null in javascript:
I think QObjectList is not supported in 5.12.0 for JS.
QObjectList is definitely supported by QJSEngine in Qt 5.12.
How did you pass the list into JavaScript?
I already verified the object is valid.
How did you do that?
-
@JonB : Thank you for the answer. I already verified the object is valid. I think QObjectList is not supported in 5.12.0 for JS. may need to check with higher version.
wrote on 6 Feb 2019, 08:05 last edited by@zosskr
I am with @JKSH on this: how do you actually know the object is valid? Because when JS says"Cannot read property 'forEach' of null" error message from javascript when I try to list of QObjectList using forEach.
that (should) mean that the lhs of whatever you are calling
forEach()
on has the valuenull
....
1/8