qtscript

Using a member function with QScriptEngine::newFunction

我与影子孤独终老i 提交于 2020-01-02 10:04:13
问题 Let's take the case of a simple class: QScriptEngine engine; class MyClass { public: QScriptValue foo(QScriptContext*, QScriptEngine*); MyClass(); }; QScriptValue MyClass:foo(QScriptContext* context, QScriptEngine* eng) { //something } MyClass::MyClass() { QScriptValue self = engine.newFunction(this->foo, 0); .... } The above function gives me an error: no matching function for call to ‘QScriptEngine::newFunction(<unresolved overloaded function type>, int)’ I have tried using engine

Setting QScriptValue-local values prior to evaluating

泄露秘密 提交于 2019-12-13 07:31:15
问题 Is it possible, in Qt 4.8, from the C++ side, to set QScriptValue -local values in a QScriptEngine ? For example, let's say I have: QScriptEngine engine; engine.globalObject().setProperty("glob", 1000); // ???: Set loc to, say, 42. QScriptValue expr1 = engine.evaluate("glob + loc"); qDebug() << expr1.toNumber(); // ???: Set loc to, say, 99. QScriptValue expr2 = engine.evaluate("glob + loc"); qDebug() << expr2.toNumber(); And I'd like the output of that to be: 1042 1099 The obvious solution to

QScriptEngineAgent - obtaining callee name

♀尐吖头ヾ 提交于 2019-12-13 05:26:58
问题 I'm trying to implement a simple QtScript performance profiler via QScriptEngineAgent , by catching function entries and exits. I successfully subscribed to QScriptEngineAgent::functionEntry() callback. Now, is it possible to obtain the name (as string) of the function which is being called, inside this callback? Even though I'm aware that not all script functions need to have a name, even in the most simple cases it doesn't seem to work. QScriptContextInfo provides facilities for that, but

Optimize QScriptEngine repeated action

我的梦境 提交于 2019-12-12 01:05:12
问题 I'm trying to optimize QScriptEngine operations in one of my functions. The function is named executeCustomJSOperation and it executes the same JS code in multiple files. However each file needs to change a global variable named $xmlData . The function basicaly loads a XML file to memory using the $xmlData variable and then always apply the same javascript code ( jsString ) to edit this XML file using javascript. In the end the $xmlData variable is updated with the edited XML again. I've got

Using a member function with QScriptEngine::newFunction

眉间皱痕 提交于 2019-12-06 06:06:55
Let's take the case of a simple class: QScriptEngine engine; class MyClass { public: QScriptValue foo(QScriptContext*, QScriptEngine*); MyClass(); }; QScriptValue MyClass:foo(QScriptContext* context, QScriptEngine* eng) { //something } MyClass::MyClass() { QScriptValue self = engine.newFunction(this->foo, 0); .... } The above function gives me an error: no matching function for call to ‘QScriptEngine::newFunction(<unresolved overloaded function type>, int)’ I have tried using engine.newFunction(reinterpret_cast<FunctionSignature>(foo), 0); but this gives me an error which basically says that

What is the equivalent of JavaScript's setTimeout on qtScript?

喜夏-厌秋 提交于 2019-11-30 02:57:04
问题 Not much to add; what is the equivalent of JavaScript's setTimeout on qtScript? 回答1: Here's how you can extend your script language, by providing a self-contained C++ method (no need for bookkeeping of timer ids or so). Just create the following slot called "setTimeout": void ScriptGlobalObject::setTimeout(QScriptValue fn, int milliseconds) { if (fn.isFunction()) { QTimer *timer = new QTimer(0); qScriptConnect(timer, SIGNAL(timeout()), QScriptValue(), fn); connect(timer, SIGNAL(timeout()),