classPiiUniversalSlot
#include <PiiUniversalSlot.h>
An object that can be used as a slot for any signal.
Inherits QObject
Description
PiiUniversalSlot has no static moc-generated slots, but itcan create a matching a slot for any signal at run time. When the slot is invoked, the call is passed to the protected invokeSlot() function that must be implemented in a subclass.
Since Qt's meta-object system relies on a static number of signals/slots in a class, classes derived from PiiUniversalSlot cannot have ordinary signals and slots.
Constructors and destructor
|
( )
|
|
Public member functions
|
int
|
(
Connects the given signal in the source object to this object. |
|
int
|
Disconnects a signal from a dynamic slot. |
Protected member functions
|
QVariantList
|
(
Converts the arguments of the slot identified by id to a QVariantList. |
|
int
|
(
Returns the number of arguments for the slot identified by id. |
|
virtual bool
|
(
Invokes the universal slot. |
|
( )
|
|
|
(
Returns the normalized signature of the slot corresponding to id. |
Function details
-
PiiUniversalSlot
()[protected] -
~PiiUniversalSlot
() -
int dynamicConnect
(- QObject * source
- const char * signal
- const char * slot = 0
- Qt::ConnectionType type = Qt::AutoConnection
Connects the given signal in the source object to this object.
If the slot already exists, the signal will be connected to it. Otherwise, a new slot will be created and assigned a unique id.
class MySlot : public PiiUniversalSlot { ... }; QObject obj; MySlot mySlot; mySlot.dynamicConnect(&obj, "destroyed()");
Parameters
- source
-
the sender of the signal
- signal
-
the signature of the signal to connect to. You can use the SIGNAL macro to wrap the signal name, but it is not necessary.
- slot
-
the signature of the dynamic slot to create. If slot is zero, signal will be used as the signature of the slot as well. You can use the SLOT macro to wrap the slot name, but it is not necessary.
- type
-
the type of the connection
Returns
the id of the slot (either new or existing), or -1 on failure.
-
int dynamicDisconnect
Disconnects a signal from a dynamic slot.
Returns
trueon success,falseon failureSee also
-
QVariantList argsToList
(- int id
- void ** args
[protected]Converts the arguments of the slot identified by id to a QVariantList.
bool MySlot::invokeSlot(int id, void** args) { QVariantList lstArgs(argsToList(id, args)); if (lstArgs.size() == 2) dealWithTwoArgs(); // ... return true; }
-
int argumentCount
(- int id
[protected]Returns the number of arguments for the slot identified by id.
-
virtual bool invokeSlot
(- int id
- void ** args
[protected, pure virtual]Invokes the universal slot.
bool MySlot::invokeSlot(int id, void** args) { if (signatureOf(id) == "valueChanged(int)") { int iValue = *reinterpret_cast<int*>(args[1]); // ... } return true; }
Parameters
- id
-
the id of the slot that was invoked
- args
-
typeless pointers to the signal's arguments. args[0] is the return value, and the rest of the values point to function call parameters, whose types match those listed in the signature.
Returns
trueif the call was successful andfalseotherwise. -
Returns the normalized signature of the slot corresponding to id.
Add a note
Not a single note added yet. Be the first, add yours.