How to iterate over items in QScriptValue which isArray()?

389 views Asked by At

So I have this code:

QScriptValue result(someFunction());
if(result.isArray()) {
{
    // Print items in array
}

How can I do it? I tried to convert it to QList<QScriptValue> but that doesn't work. I considered doing this:

    const int length = (int)result.property("length").toNumber();
    for (int i = 0; i < length; ++i) {
        const QSCriptValue entry(result.property(QString::number(i)))));
        // do something with entry
    }

It works but seems kinda ugly.

1

There are 1 answers

0
bipll On

Based on QScriptValue help, probably something like:

for(v: result.toVariant().as<QVariantList>()) {
    // here v is a QVariant-item
}

Needs testing to see if it actually.