Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.15.0
-
None
Description
Hi,
The attachment is the demo code.
The JSONObj and JSONArray is derived from QObject and registered into JSEngine by
// code placeholder QJSValue jsonObj = engine.newQMetaObject(&JSONObj::staticMetaObject); engine.globalObject().setProperty("JSONObj", jsonObj); QJSValue jsonary = engine.newQMetaObject(&JSONArray::staticMetaObject); engine.globalObject().setProperty("JSONArray", jsonary);
Below is the QML code. I print the first element in the array each time add a new element, but after about 800 times adding, the first element is recycled by the engine, and I can not print it any more . The first element is referenced by the "mainary", I want to know why it is recycled. Thank you!
// code placeholder MouseArea{ anchors.fill: parent onClicked: { var mainary = new JSONArray(); for(var ii=0;ii<2000;ii++) { var ary = new JSONArray(); for(var i =0;i<2;i++) { var obj = new JSONObj(); obj.put("name","qt_company "+ii+" "+i) // obj.put("name","qt_company ") ary.add(obj) // console.log("index "+i+" print first element: "+ary.get(0).get("name")) } // console.log("array lenghth "+ary.size()) mainary.add(ary); console.log("index : "+ii+ " print first element :"+mainary.get(0).get(0).get("name")) } } }
Log:
// code placeholder qml: index : 848 print first element :qt_company 0 0 qml: index : 849 print first element :qt_company 0 0 qml: index : 850 print first element :qt_company 0 0 qml: index : 851 print first element :qt_company 0 0 qml: index : 852 print first element :qt_company 0 0 qml: index : 853 print first element :qt_company 0 0 qml: index : 854 print first element :qt_company 0 0 qrc:/main.qml:30: TypeError: Cannot call method 'get' of null