Chapter 1. Qore Qt4 Module

Table of Contents

Signals and Slots

The qt4 module provides a Qt4 API to Qore. Classes and functions in this module follow the Qt4 C++ API so the Qt4 official documentation is the main source of informations.

Module is initialized by the following clause in the Qore scipt:

Example 1.1. Requires Clause

%requires qt4

Static methods can be called as regular Qore static method or they can be invoked with object instance too.

Signals and Slots

The mechanism of Qt4 signals and slots is implemented for this module too. Signals and slots used in the SIGNAL and SLOT functions calls have to follow C++ style. See example below.

There are some additional methods and functions in this area:

QObject::createSignal( string )

This QObject's new method is mandatory when you need to create a new, custom, signal.

QObject::connect( caller, signal, target, slot)

Static method. It's a reimplementation of C++ connect method with the same roles of arguments:

caller: a QObject based instance which will emit the signal

signal: caller's signal description in C++ style

target: a QObject based instance which will catch the signal from caller

signal: target's slot description in C++ style

QObject::connect( caller, signal, slot)

Regular (non-static) method. It's new and additional method for another way how to connect signals and slots of two QObject based objects. It's used as target.connect( caller, signal, slots ) with arguments:

caller: a QObject based instance which will emit the signal

signal: caller's signal description in C++ style

target: a QObject based instance which will catch the signal from caller

signal: target's slot description in C++ style

QObject::emit( signal, arguments )

This QObject's new method is mandatory when you need to emit a signal. The signal is a string self-representation in C++ syntax. Arguments can be 0 or more required arguments for emitted signal. Example: $.emit("mySignal(int, int, int)", 0, 2, 4);

SIGNAL( string )

Qore reimplementation of C++ SIGNAL macro. Its usage in connect methods is the same.

SLOT( string )

Qore reimplementation of C++ SLOT macro. Its usage in connect methods is the same.

Example 1.2. How to set signals and slots

class MyClass inherits QObject
{
    private $.widget;

    constructor($parent) : QObject($parent)
    {
        $.widget = new QLineEdit("foo bar");

        # register custom signal for this class
        $.createSignal("myTextChanged(QString)");

        # 1st way how to connect signal and slot
        QObject::connect($.widget, SIGNAL("textChanged(QString)"),
                         $self, SLOT("handleText(QString)"));

        # 2nd way. Method is the same, except it's called on object instance
        # $self can be replaced with any other QObject based instance
        $.connect($.widget, SIGNAL("textChanged(QString)"),
                  $self, SLOT("handleText(QString)"));

        # 3rd way - the additional connect method ($self.connect can be
        # used as a $.connect here. But it can be called on any QObject
        # based instance.)
        $.connect($widget, SIGNAL("textChanged(QString)"),
                  SLOT("handleText(QString)"));
    }

    # our slot
    handleText($string)
    {
        # $string goes as an argument for emit call
        $.emit("myTextChanged(QString)", $string);
    }
}