Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.3.1
-
None
Description
When inheriting a JavaScript class from a C++ class using prototype inheritance, the JS constructor would usually call the C++ constructor, creating a new instance of the C++ object in the process, e.g.
MyClass.call(this);
With QJSEngine, this does not seem to work, making it impossible to create multiple instances of a JavaScript class that is derived from a C++ class.
Attached a minimalistic demo of the problem.
MyWidget is a C++ class derived from QWidget, made available to scripts.
MyWidgetJS is a JS class derived from MyWidget.
The example is creating two instances of MyWidgetJS, but only one instance of MyWidget is created, making the two instances one and the same instance on the C++ level. Note that the example should create and show two widgets but only creates and shows one. The constructor of MyWidget is only called once (when creating and assigning the prototype).
The same example works fine with QScriptEngine which calls the constructor of MyWidget three times (for the prototype and each instance) but I cannot get this to work with QJSEngine. Of course, I might be missing something.