QList of pointers is broken in Js
svalaskevicius opened this issue · 4 comments
pasted from #22:
hi @svalaskevicius, I have a question about using QList in Javascript.
I was intending to use QList in Js, and i added following code segment in qtjs-generator/metagen/qtQml_cfg.js
as following:
predefinedTemplateInstances: [
'QList < QQuickGradientStop* > ', 'QList_QQuickGradientStop_Ptr',
]
And i used QList_QQuickGradientStop_Ptr in my test.js as following:
var list = new qt.QList_QQuickGradientStop_Ptr();
var stop1 = new qt.QQuickGradientStop();
var color1 = new qt.QColor("red");
stop1.setColor(color1);
console.log("in stop1:", stop1.color().value());
stop1.setPosition(0.33);
console.log("in stop1:", stop1.position());
list.append(stop1);
console.log("in list:", list.value(0).color().value());
console.log("in list:", list.value(0).position());
It comes up with the result as :
in stop1: 255
in stop1: 0.33
in list: 0
in list: 6.9415221825227e-310
In above code block, after list.append(stop1)
, it turned out the result the list is not correctly evaluated by stop1
.
Would you please help me to find out what the problem is ? Thanks a lot ~
a similar, easier to reproduce testcase:
var obj = new qt.QObject();
obj.setProperty("propName", new qt.QVariant(new qt.QString("aaa")));
console.log(obj.property("propName").toString().toLatin1().constData());
var list = new qt.QList_QObject_ptr();
list.append(obj);
console.log(list.front().property("propName").toString().toLatin1().constData());
where the last line segfaults..
Hi @yinyi26, I've created a failing test case in cpgf (see the last link referenced in this PR) for this issue for now, but as this is a rather complicated one, I'll have to come back on that later when I have a bit more time..
Is this issue urgent for you?
Thanks @svalaskevicius a lot for your quick response, it is not so urgent for me. However in future maybe i still need to use QList of Pointer in JS, i will keep on watching on this issue :)
Hi @yinyi26,
@wqking has fixed the underlying issue and I can confirm it solves the problem with QList of pointers :)
I've updated cpgf in the master branch, but as it has more changes now (update to Qt5.3.2), you might want to try first by just these commands:
cd lib/cpgf
git checkout 3affe48
cd ../cpgf-build/build
rm libcpgf.so
make -j4
cd ../../../build/
make -j4
Hope it helps - please let me know if you find any more issues :)
Thanks!
Hi @svalaskevicius @wqking, I have confirmed it works fine. Thanks a lot ~