Accessing QtScript arrays from C++
I wondering how to access an (QScript) array from C++.
We can use QScriptValue::isArray() to determine if the value is an array or not. Unfortunately, it doesn’t really
state there how to access contents of the array.My initial reaction was to just convert the value to a
QVariant (using toVariant()) and then convert the variant to a QVariantList (toList()). That didn’t quite work.
Re: Accessing QtScript arrays from C++
Works for me. Can you post your code?
Code:
#include <QtGui>
#include <QtScript>
int main(int argc, char * argv[])
{
QScriptEngine eng;
QScriptValue val = eng.evaluate("[1, 2, 3, 'four', 'five']");
qDebug() << val.isArray();
QVariantList arr = val.toVariant().toList();
{
qDebug() << item;
}
return 0;
}