C

Signal Struct

struct Qul::Signal

Allows creating a signal that can be connected from QML. More...

Header: #include <qul/signal.h>
Since: Qt Quick Ultralite 1.0

Public Functions

bool isConnected() const
void operator()() const

Detailed Description

When you put a signal as a member of a class that derives from Qul::Object or Qul::Singleton, the qmlinterfacegenerator tool will generate a signal that can be connected from the QML code using the onXxxx:{...} syntax.

The template argument of the Signal shall be a function signature, including the parameters names which are used by qmlinterfacegenerator to expose them to qml.

Example:

class MySingleton : public Qul::Singleton<MySingleton> {
public:
    Qul::Signal<void()> changed; // signal without arguments
    Qul::Signal<void(int key, qreal value)> newValue; // signal with arguments
};

This can be used from QML like so:

MySingleton.onNewValue: console.log("Got a new value for key", key, ": ", value);

In order to emit the signal from the C++ code, you can use the operator().

MySingleton::instance().newValue(1, 3.141592);

If signal member is called exactly as the QML signal handler it will be treated as signal named without on prefix and starting with lower case letter.

Example:

class MyObject : public Qul::Object {
public:
    Qul::Signal<void()> onFoo; // signal named as QML signal handler
};

This can be used from QML like so:

Item {
    MyObject {
        id: myObject
        onFoo: console.log("Foo signal invoked.")
    }

    MouseArea: {
        onClicked: myObject.foo();
    }
}

Member Function Documentation

bool Signal::isConnected() const

Returns true if any slots or QML signal handlers are connected to this signal instance, otherwise returns false.

Note: Slots are not part of public API offered by Qt Quick Ultralite at the moment

void Signal::operator()() const

Emit the signal.

Note: This call operator will have arguments if the template argument T is not void or empty.

Available under certain Qt licenses.
Find out more.