KJSEmbed::KJSEmbedPart : Main API for KJSEmbed.
KJSEmbed::JSConsoleWidget : A widget that provides an interactive JS console.
: Defines a security policy for .
KJSEmbed::JSConsoleWidget *win = new KJSEmbed::JSConsoleWidget(); win->show();The embedding application can run scripts in the console using the execute() method.
The best way to use KJSEmbed is keep control of the interpreter yourself using the KJSEmbedPart, this way you can make parts of your application available to scripts. The following example creates its own interpreter then binds it to the console:KJSEmbed::KJSEmbedPart *js = new KJSEmbed::KJSEmbedPart(); KJSEmbed::JSConsoleWidget *console = js->view();
The following code shows how easy it is to make an object available for scripting. It creates a QVBox containing two QLabels then makes them visible to KJSEmbed:QVBox *toplevel = new QVBox( 0, "box" ); QLabel *title = new QLabel( "Some Title", toplevel, "title"); QLabel *main = new QLabel( "Some text, more text.", toplevel, "main" );
js->addObject( title ); js->addObject( main, "text" );
The slots of a QObject bound to the interpreter are made available to scripts as if they normal methods. In the example above, we could conceal the label 'main' entirely by calling its hide() slot:main.hide()
Access To the QObject TreeAs well as providing script access to an individual widget, KJSEmbed allows scripts to walk the object tree and access others. If we modified the previous example to publish the QBox widget 'toplevel' as follows:js->addObject( toplevel, "window" );Then, despite the fact we've only explicitly published a single widget, we've also provided access to both 'main' and 'title'. The ability to navigate the object tree is limited by the SecurityPolicy, the default policy only allows scripts access to children of the published object.
To achieve the same result as before, we could use script like this:window.child("main").text = "World" window.child("main").text = "Hello " + window.child("main").textThe result of this script is identical to the previous example.
Generated on Sat May 29 03:13:07 2004 for KJSEmbed by 1.3.2