How to pass QVariantList from a c++ function to QtScript function ?
-
Hi,
How to to pass QVariantList from a c++ function to QtScript function ?
example:
qt script:
function evaluate( var valueList )
{
var output = valueList[0] + valueList[1];
return output;
}How to pass value to the above qt script from the c++ code?
I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
The valueList above contains qreal values. QVariantList contains QList<QList<qreal> > -
Hi,
How to to pass QVariantList from a c++ function to QtScript function ?
example:
qt script:
function evaluate( var valueList )
{
var output = valueList[0] + valueList[1];
return output;
}How to pass value to the above qt script from the c++ code?
I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >First of all the QtScript module is deprecated.
If you do not depend on QtScript you should rather use QJSEngine (from the QtQml module) - or even QQmlEngine if you like.The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >
A nested QList wont make it to QtScript/QML.
Only nested QVariantLists is possible in this case.For a better understanding. If you need to pass something from C++ to QtScript/QML everything should be a packed into a QVariant.
You might also want to take a look at the implicit type conversions.
I dont know if this is handled by QJSEngine or only by QQmlEngine though. But anyway you can use QQmlEngine as i said. -
Hi,
How to to pass QVariantList from a c++ function to QtScript function ?
example:
qt script:
function evaluate( var valueList )
{
var output = valueList[0] + valueList[1];
return output;
}How to pass value to the above qt script from the c++ code?
I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
The valueList above contains qreal values. QVariantList contains QList<QList<qreal> > -
@QtVik Hi,
Use QScriptEngine::toScriptValue<T>() :
QVariantList listIn; listIn << 123 << "hello"; QScriptValue array = scriptEngine->toScriptValue(listIn);