QML - Passing Javascript associative array to C++ -
in app have class registered singleton qml. purpose collecting values in qml associative array , passing array c++. simplified version of class:
class config : public qobject { q_object private: config(qobject *parent = 0); public: static config *instance(); ~config(); q_invokable void sendvalue (const qvariantmap &map) { qwarning() << map.size(); } } and here register instance of class singleton:
class="lang-cpp prettyprint-override">qmlregistersingletontype<config>("myns", 1, 0, "config", config_singletontype_provider); in place in qml file seek pass javascript array c++;
class="lang-js prettyprint-override">function sendvalue() { var arr = []; arr["key"] = "value"; config.sendvalue(arr); } but nil passed. map.size() in c++ returns 0. may need additional conversion?
ok, reply own question ) documentation not clear but, understand, qt converts js array qvariantlist , js object qvariantmap in case need create object, not array:
var arr = {}; javascript c++ arrays qml qt-quick
No comments:
Post a Comment