Details
-
Suggestion
-
Resolution: Done
-
P2: Important
-
None
-
None
-
2b5fb185627f8adfb6c5b3d62990a58429bf4ea7 (qtdeclarative)
Description
In QtScript there’s the qScriptRegisterMetaType() function that registers custom types using custom conversion functions. This would allow me to register the following class for example:
class Point3D { public: int x; int y; int z; Point3D() = default; Point3D(int x, int y, int z); bool operator==(const Point3D &other) const; bool operator!=(const Point3D &other) const; Point3D operator+(const Vector3D &vector) const; Point3D operator-(const Vector3D &vector) const; Vector3D operator-(const Point3D &other) const; QString toString() const; static QScriptValue toScriptValue(QScriptEngine *engine, const Point3D &point); static void fromScriptValue(const QScriptValue &object, Point3D &point); };
The last two functions were passed to qScriptRegisterMetaType() and would do the actual conversion, which in this case converted the point to a JS array with 3 elements. Important to note is that the Point3D class does not inherit from QObject; it’s a POD.
I believe the above use-case should be enabled using QJSEngine.
Converting all types to QObject is really not an option for me and to make matters worse, I even have some QObject-based classes that will still need custom conversion functions as the conversion is more complex than a simple call to QJSEngine::newQObject(). Therefore I really need an equivalent to qScriptRegisterMetaType() that will work with QJSEngine.
Attachments
Issue Links
- is required for
-
QTBUG-35361 Create an application scripting library for advanced JS integration
-
- Open
-
- replaces
-
QTBUG-39584 Ability to add basic types to QML
-
- Closed
-
For Gerrit Dashboard: QTBUG-29769 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
100347,16 | Enable gadget wrapping for custom value types | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |