PDA

View Full Version : Using Javascript in Qt



sipahi
31st January 2013, 10:04
Is it possible to use javascript functions in my Qt desktop project?
If yes, can you show some example like how can I define function?
I always find QML examples on the net but my project is a desktop project.

wysota
31st January 2013, 10:33
Is it possible to use javascript functions in my Qt desktop project?
Yes.

If yes, can you show some example like how can I define function?


QScriptEngine engine;
//...
QScriptValue fun = engine.evaluate("(function() { return 7; })");
// ...

int retVal = 0;
if(fun.isFunction()) {
retVal = fun.call().toInt32();
}

sipahi
31st January 2013, 12:45
thank you for your answer @wysota.

anda_skoa
31st January 2013, 16:34
Qt Documentation has a couple of examples around the topic of using QtScript
http://qt-project.org/doc/qt-4.8/examples-script.html

Cheers,
_