Signal Struct

struct Qul ::Signal

Allows creating a signal that can be connected from QML. 更多...

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

This struct was introduced in Qt Quick Ultralite 1.0.

公共函数

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

详细描述

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.

范例:

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.

范例:

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();
    }
}
							

成员函数文档编制

bool Signal:: isConnected () const

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

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

void Signal:: operator() () const

Emit the signal.

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