Qt QScriptEngine and default conversions from Qt Script to C++
I'm trying to convert a QVariantMap to Qt Script object. If I understood correctly it should go something like this:
QScriptEngine* engine = new QScriptEngine();
QVariantMap* test = new QVariantMap();
test.insert("testkey", QString("testvalue"));
QScriptValue testqs = engine->toScriptValue(test);
QString value = testqs.property("testkey").toString();
I'm not sure if that is th开发者_JAVA技巧e right way to event try to ask for the value from the ScriptValue. But the root problem is that the Script object I get, doesn't seem the have any of the properties that were in the map to begin with.
So, what am I missing?
Ok, so I figured out my problem. If I would have read the specs correctly I would have noticed that the toScriptValue() method won't take a pointer. So the fix was:
QScriptValue testqs = engine->toScriptValue(*test);
精彩评论