This page is under construction. This page is actively being developed and updated with new information, and may be incomplete. You can help by editing this page

This tutorial shows how to use a system of signals and slots to provide a scripting interface for a KDE application. It builds upon the Kross Hello World tutorial and again follows a 'Hello World' type format.

The changes are addition of a text entry field and the reorganisation of logic handling the Kross::Action. Note also that there is no code in mainwindow.cpp to set the label, as there was in the previous tutorial. Instead, Objects are simply made available to the scripting interface through the action->addObject calls, without any knowledge of what the script will use them for. This removes the need to know at the time of writing the application what function the scripts will perform, and is therefore suited to a plugin interface.

krossSigsSlots.py

This script catches the textChanged SIGNAL of the QLineEdit, and connects it to a simple python function to reverse the string in the QLineEdit and display it in the QLabel.

!/usr/bin/env kross

import MyLabel
import MyInterpreter
import MyInputString

def reverseString(s):

s = s[::-1]
MyLabel.text = s

MyInputString.connect("textChanged(const QString &)", reverseString)

krossSigsSlots.js

This script does the same like the script above but using the JavaScript scripting language.

Autoconnecting Signals and Slots

It is possible to connect signals from your Object to slots in your script file automatically. Edit the mainwindow.cpp file to add another argument to the addObject function:

action->addObject(txtInputString, "MyInputString",

Kross::ChildrenInterface::AutoConnectSignals);

action->addObject(cmbInterpreters, "MyInterpreter");
action->addObject(lblMessage, "MyLabel");
The Kross::ChildrenInterface::AutoConnectSignals argument causes signals of the object to be automatically connected with scripting functions of the same name. Therefore, the scripts can again be simplified: