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>
impl<A> Signal<A>
sourcepub unsafe fn new(
q_object: impl CastInto<Ref<QObject>>,
receiver_id: &'static CStr
) -> Self
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>
impl<SignalArguments> Signal<SignalArguments>
sourcepub unsafe fn connect_with_type<R>(
&self,
connection_type: ConnectionType,
receiver: R
) -> CppBox<Connection>
pub unsafe fn connect_with_type<R>( &self, connection_type: ConnectionType, receiver: R ) -> CppBox<Connection>
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 QObject
s referenced by self
and receiver
must be alive.
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.
sourcepub unsafe fn connect<R>(&self, receiver: R) -> CppBox<Connection>
pub unsafe fn connect<R>(&self, receiver: R) -> CppBox<Connection>
Creates a Qt connection between this signal and receiver
, using auto connection type.
See connect_with_type
for more details.