This is already possible :) just use var properties, they map to QJSValue in C++.
Simon Fra: Sebastian Lehmann Sendt: 19:31 onsdag 8. januar 2014 Til: [email protected] Emne: [Development] Builtin QML property type for functions possible? Hi guys, We can write JS functions in QML, but they can't be passed around via properties. The type "variant" can't be assigned a JS function. Can either the possibility of such an assignment (to "variant" properties) or a "function" property type be added to the QML core? I'm not asking for someone to do it, but I'd like to know if it is possible (with reasonable effort) to do so, as I think this might be a nice extension. In which scenarios would this feature help? Can't we use signals and slots for C++/QML interoperability? Well, there are some scenarios in which we want to pass "behavior" from C++ to QML. This could always be wrapped in a QObject with a slot to be called, but such a wrapper can't be created with little effort / nice syntax from within QML to pass a behavior back to C++, afaik. The following would then be possible: Assign something like a callback from C++ to a QML property (maybe using some QQmlFunctionProperty type as a wrapper, like we have one for list properties; this could wrap around any "callable" thing like std::function does). Then a call this function from QML's JS like it were a JS function; also assign a function from QML to such a property and call it in C++ (the QQmlFunctionProperty then wraps around a function of the underlying JS engine and has `operator()()` or `invoke()`, or similar). Signature is of course a problem, but only supporting `void()` would be a start. `QVariant(QVariantList)` could make it flexible yet ugly and slow. It would also be cool to first try to find the nicest way to do both things with the existing tools. Thanks for any feedback on this topic! Cheers, Sebastian Lehmann _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
_______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
