PDA

View Full Version : QtScript and arrays



supergillis
20th May 2009, 20:01
I can make an array in QEngine and evaluate it, but I don't have any idea of how to get each element of the array to a QStringList or a normal QList...
This is probably a stupid question since I can't find anything on this forum about it :). But I'm asking it anyway because I really want to know it!

Here's what I already got:

QScriptValue array = engine.evaluate("new Array(\"a\", \"b\", \"c\")");
QVariant var = array.toVariant();
if(var.canConvert<QStringList>())
{
QStringList list = var.value<QStringList>();
qDebug() << "can convert";
qDebug() << list.count();
while(list.count())
qDebug() << list.takeAt(0);
}
And this is the output:

can convert
1
"a,b,c"
As you can see, the QStringList only contains one element: "a,b,c"...

Thanks,
Gillis

supergillis
20th May 2009, 20:13
Nevermind, I already found out.

QScriptValue array = engine.evaluate("new Array(\"a\", \"b\", \"c\")");
int length = array.property("length").toInteger();
for(int i = 0; i < length; i++)
qDebug() << array.property(i).toString();

Thanks anyway ;)
Gillis