Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
Description
There is no way to define Symbol-identified properties and methods for Q_OBJECT and Q_GADGET objects, propagated to qml-js for using from qml. For concrete example - Symbol.iterator is exclusively used inside the js-engine to fetch iterator from an iterable objects, so, there is no way to use a QObject or gadget as iterable.
Suggestion: add a way to define Symbol-identified properties and methods for Q_OBJECT and Q_GADGET objects, propagated to qml-js.
Syntactically that can be done through
- Q_CLASSINFO or
- invocable method tag,
plus the appropriate support from qml and js engines. Example
class MyGadget { Q_GADGET; Q_CLASSINFO("@@Symbol.iterator", "myIteratorMethod"); public: Q_INVOCABLE MyIterator myIteratorMethod(); }; //or class MyGadget { Q_GADGET; public: Q_JS_ALIAS("@@Symbol.iterator") Q_INVOCABLE MyIterator myIteratorMethod(); };
Another way - provide an ability to register a programmer-defined js-prototype (QJSValue or similar js-object) for concrete Q_OBJECT/Q_GADGET c++ types. These prototypes will be automatically settled as prototypes for converted objects, instead of (or as a base of) QV4::ExecutionEngine::ValueTypeProto (and similar for Q_OBJECT). Example
// programmer builds js-prototype object QJSValue myGadgetProto = jsEngine->evaluate("let res = {}; res[Symbol.iterator] = function() {/*blabla..*/}; return res"); //and registers it for a some value-type as prototype qQmlRegisterValueTypeProto<MyGadget>(myGadgetProto); // and for qobject-based qQmlRegisterQObjectDerivedProto<MyQObjectBased>(myProto); //... qml-js engine will use provided prototypes for wrapped gadgets/qobjects
Or some similar..