Struct qt_core::Signal

source ·
pub struct Signal<Arguments>(/* private fields */);
Expand description

Reference to a particular signal of a particular object.

The Arguments generic argument specifies argument types of this signal.

Implementations§

source§

impl<A> Signal<A>

source

pub unsafe fn new( q_object: impl CastInto<Ref<QObject>>, receiver_id: &'static CStr ) -> Self

Creates a Signal than references a signal of q_object identified by receiver_id.

This function should not be used manually. It’s normally called from functions generated by ritual. receiver_id is the ID returned by Qt’s SIGNAL C++ macro.

Safety

q_object must contain a valid pointer to a QObject-based object. The object must outlive the created Signal object.

source§

impl<SignalArguments> Signal<SignalArguments>

source

pub unsafe fn connect_with_type<R>( &self, connection_type: ConnectionType, receiver: R ) -> CppBox<Connection>
where R: AsReceiver, SignalArguments: ArgumentsCompatible<R::Arguments>,

Creates a Qt connection between this signal and receiver, using the specified connection_type.

Returns an object that represents the connection. You can use is_valid() on this object to determine if the connection was successful.

The connection will automatically be deleted when either the sender or the receiver is deleted.

Safety

The QObjects referenced by self and receiver must be alive.

C++ documentation:

Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns a handle to the connection that can be used to disconnect it later.

You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:

QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
                 label,  SLOT(setNum(int)));

This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:

// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
                 label, SLOT(setNum(int value)));

A signal can also be connected to another signal:

class MyWidget : public QWidget
{
    Q_OBJECT
public:
    MyWidget();
signals:
    buttonClicked();
private:
    QPushButton *myButton;
};
MyWidget::MyWidget()
{
    myButton = new QPushButton(this);
    connect(myButton, SIGNAL(clicked()),
            this, SIGNAL(buttonClicked()));
}

In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.

A signal can be connected to many slots and signals. Many signals can be connected to one slot.

If a signal is connected to several slots, the slots are activated in the same order in which the connections were made, when the signal is emitted.

The function returns a QMetaObject::Connection that represents a handle to a connection if it successfully connects the signal to the slot. The connection handle will be invalid if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible. You can check if the handle is valid by casting it to a bool.

By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return an invalid QMetaObject::Connection.

Note: Qt::UniqueConnections do not work for lambdas, non-member functions and functors; they only apply to connecting to member functions.

The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message

QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)

call qRegisterMetaType() to register the data type before you establish the connection.

Note: This function is thread-safe.

See also disconnect(), sender(), qRegisterMetaType(), Q_DECLARE_METATYPE(), and Differences between String-Based and Functor-Based Connections.

source

pub unsafe fn connect<R>(&self, receiver: R) -> CppBox<Connection>
where R: AsReceiver, SignalArguments: ArgumentsCompatible<R::Arguments>,

Creates a Qt connection between this signal and receiver, using auto connection type.

See connect_with_type for more details.

Trait Implementations§

source§

impl<A> AsReceiver for Signal<A>

§

type Arguments = A

Argument types expected by this receiver.
source§

fn as_receiver(&self) -> Receiver<A>

Returns information about this receiver.
source§

impl<A> Clone for Signal<A>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A> Debug for Signal<A>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A> Copy for Signal<A>

Auto Trait Implementations§

§

impl<Arguments> RefUnwindSafe for Signal<Arguments>
where Arguments: RefUnwindSafe,

§

impl<Arguments> !Send for Signal<Arguments>

§

impl<Arguments> !Sync for Signal<Arguments>

§

impl<Arguments> Unpin for Signal<Arguments>
where Arguments: Unpin,

§

impl<Arguments> UnwindSafe for Signal<Arguments>
where Arguments: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.