I have a set of C++ classes exposed to javascript in Qt 5, based on the QJSEngine (because Qt script seems to be deprecated).
My QObject-derived classes A and B have the Q_OBJECT macro and use the Q_DECLARE_METATYPE macro as well.
I have exposed factory functions for my classes that allow me to create new instances from inside javascript. All the following works fine:
a = namespace.createNewA(); // QJSEngine reports a type A object
b = namespace.createNewB(); // QJSEngine reports a type B object
b.SetParent(a); // SetParent is a slot of B taking a const A& parameter, gets called correctly
// But now.
b.GetParent(); // Reports QVariant(A), even though this is a slot: A GetParent() const
Is there a way for me to ensure that GetParent in javascript gets recognized as an actual type A object, instead of a QVariant?
I figured out the issues with my original code:
This required some changes to my code setup, because the returned value used to be a temporary, but I can live with that.