Questions tagged [qjsengine]

Provides an environment for evaluating JavaScript code

The QJSEngine class provides an environment for evaluating JavaScript code

40 questions
2
votes
1 answer

Custom C++ type to QJSEngine: member function return value is always QVariant

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…
Joris Timmermans
  • 10,814
  • 2
  • 49
  • 75
1
vote
1 answer

C++ QT Call C++ function in QJSEngine

I'm trying to call a function which is implemented in C++ to call in a JS function, which gets evaluated with the QT QJSEngine. So far I have tried this class Person : public QObject { Q_OBJECT public: Q_INVOKABLE cppFunction(int a); …
Lockna
  • 691
  • 1
  • 8
  • 24
1
vote
1 answer

QJSEngine, global and script, what is causing the syntax error

I am using the QJSEngine, I added a global to the object: QJSValue objGlobal = pobjScriptEng->globalObject(); pobjScriptEng is a pointer to an instance of QJSEngine. I have a map of globals, the map type definition: std::map
SPlatten
  • 5,334
  • 11
  • 57
  • 128
1
vote
1 answer

How to register an enum type to QJSEngine to be used from the scripting environment?

I've searched for hours on end but I cannot figure out how do I register an enum type from C++ side so I can use it from the scripting environment side when using QJSEngine? I have a class that derives from QObject, is registered to the scripting…
Dago
  • 1,349
  • 1
  • 11
  • 19
1
vote
0 answers

How javascript callstack, queue handles http request inside promise

I am understanding how the js engine handles promises then I got this great article https://medium.com/@jitubutwal144/javascript-how-is-callback-execution-strategy-for-promises-different-than-dom-events-callback-73c0e9e203b1. This made me very much…
Geetanshu Gulati
  • 692
  • 8
  • 13
1
vote
3 answers

Convert QJsonObject to Javascript object

As qt docs on QJSValue, QJsonObject ins't implicitly convertible to QJSValue, I want to call a javascript function with QJSEngine from C++, the arguments should be passed with QList to call function of another QJSValue which holds the…
e.jahandar
  • 1,715
  • 12
  • 30
1
vote
0 answers

How to use QJSEngine to access a child of a QObject in js script?

From the official qt doc, it says: Signals and slots, properties and children of object are available as properties of the created QJSValue. So I expect to access the children of a QObject, but I do not find the right way to do it. I have code as…
ricky
  • 2,058
  • 4
  • 23
  • 49
1
vote
1 answer

Speed of Javascript executed inside Qt with QJSEngine

Background: I am working in a project that requires the following: the user can write commands to perform some mathematical operations with internal variables of the main program (a GUI written in Qt/C++). My approach is a text box where the user…
pablo_worker
  • 1,042
  • 9
  • 26
1
vote
1 answer

How to instantiate c++ objects with QJSEngine

Is it possible to declare a C++ class to QJSEngine (the engine for QML) so objects of that class can be instantiated from javascript? The only solution I can come up so far is to create a factory method with Q_INVOKABLE that returns an object using…
Jay
  • 13,803
  • 4
  • 42
  • 69
1
vote
1 answer

Access dynamic property in QJSEngine

I can access properties of QObjects passed into a QJSEngine, but why can't I access dynamic properties? auto myObject = new MyObject(); // Contains a single property 'myProp'. QJSEngine engine; auto scriptMyObject = engine.newQObject( myObject…
cmannett85
  • 21,725
  • 8
  • 76
  • 119
0
votes
0 answers

QJSEngine does not know how to handle Qt basic types

I have a c++/qt application that I made scriptable via a QJSEngine my_eng in which I expose my QWidget my_obj via my_eng.globalObject().setProperty("my_obj", my_eng.newQObject(my_obj)); Now from within JS I can call all methods of my_obj. I have a…
bibi
  • 3,671
  • 5
  • 34
  • 50
0
votes
0 answers

Register inherited QObject's meta object to QJSEngine

I would like to inherit the QObject class, and register the inherited class's meta object to a QJSEngine instance, so that I can call let instance = new TrialObject(); in JavaScript. Here is my code: from PyQt6.QtQml import QJSEngine from…
SamG101
  • 488
  • 1
  • 7
  • 18
0
votes
1 answer

Is it valid to call QJSEngine::newQObject() in a C++ function called by a script?

Consider this example: ObjectCreator is set as global property via QJSEngine: // ObjectCreator is exposed to engine_ env as global property class ObjectCreator : public QObject { Q_OBJECT public: ObjectCreator(QJSEngine * engine, QObject *…
hannes
  • 1
0
votes
1 answer

Can I retain ownership of QObjects passed to QJSEngine?

I'm using QJSEngine and binding some objects with engine.globalObject().setProperty(name, engine.newQObject(obj)); The problem is that QJSEngine destructor is calling the destructors of those objects but I want them to outlive the QJSEngine…
MattBas
  • 156
  • 2
  • 7
0
votes
2 answers

Register custom type in Qt with QJsEngine

I have a custom class named LObject, with a method "test" i want to call.I have a method registered in a QJSEngine that returns an instance of LObject. I get the error message when executing the method : "Error: Unknown method return type:…
Pylvain
  • 110
  • 1
  • 7