I know I can use below way to expose QStringList to QtScript, but how can I expose a QVariantHash?
QStringList l;
l<<"2";
QScriptValue v = qScriptValueFromSequence(&engine, l);
engine.globalObject().setProperty("v", v);
For standard containers qScriptValueFromSequence()
is running fine. For other types you probably will have to create your own conversion function, take a look at qScriptRegisterMetaType()
.
you can use engine.toStriptValue() to expose QVariantMap to QtScript
QVariantMap map;
map["a"] = 3;
map["b"] = 4;
QScriptValue v = engine.toScriptValue(map);
engine.globalObject().setProperty("m", v);
engine.evaluate("var h = new Haha()");
qDebug()<<engine.evaluate("h.add(m)").toString();