Macro qml::Q_OBJECT [] [src]

macro_rules! Q_OBJECT {
    (
        pub $obj:ident as $wrapper:ident{
            signals:
            $(fn $signalname:ident ( $( $signalvar:ident : $signalqtype:ident ),* );)*

            slots:
            $(fn $slotname:ident ( $( $slotvar:ident : $slotqtype:ident ),* );)*

            properties:
            $($propname:ident : $proptype:ident; read: $read_slot:ident, write: $write_slot:ident,
                notify: $notify_sig:ident;)*
            }) => { ... };
}

Marks the structure to be able to be used in Qt meta-object system.

Examples

pub struct Example;

impl Example {
    pub fn simple_receiver(&mut self) -> Option<&QVariant> {
        // This is a function that also will be a slot
        None
    }
}

Q_OBJECT!(
pub Example as QExample{
    signals:
        fn simple_signal(s: String);
    slots:
        fn simple_receiver();
    properties:
        name: String; read: get_name, write: set_name, notify: name_changed;
});

// ...

let qobject = QExample::new(Example, "My name".into());
qobject.simple_signal("Hi from Rust!".into());