Attribute Macro qt_core::slot

source ·
#[slot]
Expand description

Generates a method that returns a slot object bound to self.

Usage

This attribute may be used on methods:

impl TodoWidget {
    #[slot(SlotNoArgs)]
    unsafe fn on_add_clicked(self: &Rc<Self>) {
        //...
    }
}

The type of slot wrapper (e.g. SlotNoArgs) must be specified as an argument to the attribute. This type must be in scope.

The macro generates another method that is called slot_{original_name} and can be used for making a connection like this:

self.form.add.clicked().connect(&self.slot_on_add_clicked());

The method accepts a &Rc<Self> and returns a QBox<Slot>, where Slot is the slot wrapper type passed to the attribute. The slot wrapper retains a weak reference to Self, so it doesn’t prevent deletion of the object.

Note that each invokation of the slot getter will create a new object.

Requirements

  • Target method must have self: &Rc<Self> argument.
  • The rest of the arguments must correspond to arguments expected by the specified slot wrapper type.
  • Self must implement StaticUpcast<QObject>. Created slots will use the result of this conversion as the parent object.