Bind class to QJSEngine not being QObject
-
Hello,
I would like to expose some classes (more than 200) to QJSEngine. I don't want to inherit from QObject in my classes, so that discards Q_INVOKABLE or slots options. Just a normal binding like LUA or V8JS would do.
Is there any way to do this?Regards
JAPA
-
@JAPA
When I say I dont want, in fact it is I can't. I cannot inherit my class from QObject for two reasons (1. many many classes, 2, Some of them are used in lists and they are instanced millions of times, so that would increase the memory footprint), -
@JAPA Are you going to have these millions of objects inside the engine all at the same time?
I have run into major speed issues doing Javascript calculations for just 4000 objects. I had to create specific C++ functions to manipulate data in C++ as the JS was too slow.
If you are going to window (expose a few at a time using a model) then you can expose information about the objects to QML/JS a bit at a time. Even a temporary QObject that references the object/objects you want to manipulate in the engine. I cannot imagine it will be performant at all to inject millions of objects into the js engine at the same time.
-
@fcarney
Hello, Thanks for answering.No, I am not going to have that amount into the JS engine at the same time, but i can send any of these objects to the engine at any time.
My current solution is to serialize (into JSON) the one I want to send to the JS engine and then deserialized inside the engine which is slow the traffic is high.
That forces me to have two implementations of the same class. One for C++ and one for JS. I don't use the objects as simple storage. They have functionality so I need methods.
I don't get the idea of the temporary object. How would you do it? Ant the end of the day I would need to access the methods in my C++ class, and I don't down how the temporary QObject would access those methods.
Thanks!
-
@JAPA I would probably use a model and expose the objects you are currently manipulating. Look up qt model/view concepts. With a model one interface object can expose a whole set.
It will most likely require a bit of work to expose what you want to the js engine.