CopperSpice API  1.9.2
QMetaMethod Class Reference

The QMetaMethod class provides meta data for a given method. More...

Public Types

enum  Access
 
enum  MethodType
 

Public Methods

Access access () const
 
const QMetaObjectgetMetaObject () const
 
template<class R , class... Ts>
bool invoke (QObject *object, CSReturnArgument< R > retval, Ts &&...Vs) const
 
template<class R , class... Ts>
bool invoke (QObject *object, Qt::ConnectionType type, CSReturnArgument< R > retval, Ts &&...Vs) const
 
template<class... Ts>
bool invoke (QObject *object, Qt::ConnectionType type, Ts &&...Vs) const
 
template<class... Ts>
bool invoke (QObject *object, Ts &&...Vs) const
 
bool isValid () const
 
int methodIndex () const
 
const QStringmethodSignature () const
 
MethodType methodType () const
 
const QString name () const
 
int parameterCount () const
 
QList< QStringparameterNames () const
 
uint parameterType (int index) const
 
QList< QStringparameterTypes () const
 
int revision () const
 
const QStringtag () const
 
const QStringtypeName () const
 

Static Public Methods

template<typename SignalClass , typename... SignalArgs>
static QMetaMethod fromSignal (void (SignalClass::*signalMethod)(SignalArgs...))
 

Friends

bool operator!= (const QMetaMethod &method1, const QMetaMethod &method2)
 
bool operator== (const QMetaMethod &method1, const QMetaMethod &method2)
 

Detailed Description

The QMetaMethod class provides meta data about a particular method in a given class. The meta data consists of various attributes like the method type, return type, full signature, and the parameter names and types. The methods for this class are used only to retrieve the meta information, like methodType() and methodSignature().

Once you have the QMetaObject for a given class, you can retrieve the QMetaMethod object for any registered method in that class.

The QMetaMethod::invoke() method is used to call the method denoted in the QMetaMethod object. This may be useful when designing a plugin based system and the methods may not be known at compile time.

A method is only registered with the meta object system if it is a signal, slot, or declared with the CS_INVOKABLE() macro. Constructors can also be registered with CS_INVOKABLE().

See also
QMetaObject, QMetaEnum, QMetaProperty, Property System

Member Enumeration Documentation

This enum describes the access levels for QMetaMethod.

ConstantValue
QMetaMethod::Private0
QMetaMethod::Protected1
QMetaMethod::Public2

This enum describes the method types for QMetaMethod.

ConstantValueDescription
QMetaMethod::Method0 Method is a not a signal, slot, or constructor
QMetaMethod::Signal1 Method is a signal
QMetaMethod::Slot2 Method is a slot
QMetaMethod::Constructor3 Method is a constructor

Method Documentation

Access QMetaMethod::access ( ) const

Returns the access specification of this QMetaMethod object, which is private, protected, or public.

See also
methodType()
template<typename SignalClass , typename... SignalArgs>
QMetaMethod QMetaMethod::fromSignal ( void (SignalClass::*)(SignalArgs...)  signalMethod)
static

Returns either the meta method that corresponds to the given signalMethod or an invalid QMetaMethod if signalMethod is not a signal of the class.

const QMetaObject * QMetaMethod::getMetaObject ( ) const

Returns the QMetaObject for the current QMetaMethod.

template<class R , class... Ts>
bool QMetaMethod::invoke ( QObject object,
CSReturnArgument< R >  retval,
Ts &&...  Vs 
) const

This overload always invokes this QMetaMethod object using the connection type Qt::AutoConnection.

template<class R , class... Ts>
bool QMetaMethod::invoke ( QObject object,
Qt::ConnectionType  type,
CSReturnArgument< R >  retval,
Ts &&...  Vs 
) const

Invokes this QMetaMethod on the given object. Returns true if the call was possible, returns false if this QMetaMethod is empty, invalid, or the parameters in Vs do not match. The call can be either synchronous or asynchronous, and will depend on the enum value for type.

The Qt::ConnectionType can be one of the following enum values.

Qt::DirectConnection
Called immediately
Qt::QueuedConnection
An event will be posted and called when the application enters the main event loop
Qt::AutoConnection
Called immediately if the given object lives in the current thread, otherwise the call is queued

The return value for this QMetaMethod object is placed in retval. If the call is queued the return value can not be evaluated and you must enclose the return value in a Q_RETURN_ARG() macro. This macro takes a type name and a non-const reference.

The following is an example to asynchronously invoke the animateClick() slot on a QPushButton.

int methodIndex = pushButton->metaObject()->indexOfMethod("animateClick()");
QMetaMethod method = metaObject->method(methodIndex);
method.invoke(pushButton, Qt::QueuedConnection);

The following is an example to synchronously invoke the compute(QString, int, double) slot on obj and retrieve its return value. QMetaObject::normalizedSignature() is used to ensure the format of the signature is what invoke() expects.

QString retval;
QString normalizedSignature = QMetaObject::normalizedSignature("compute(QString, int, double)");
int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature);
QMetaMethod method = metaObject->method(methodIndex);
method.invoke(obj, Qt::DirectConnection, Q_RETURN_ARG(QString, retval), QString("sqrt"), 42, 9.7);
See also
Q_RETURN_ARG(), QMetaObject::invokeMethod()
template<class... Ts>
bool QMetaMethod::invoke ( QObject object,
Qt::ConnectionType  type,
Ts &&...  Vs 
) const

This overload ignores the return value when this QMetaMethod object is called.

template<class... Ts>
bool QMetaMethod::invoke ( QObject object,
Ts &&...  Vs 
) const

This overload invokes this QMetaMethod object using the connection type Qt::AutoConnection and ignores the return value.

bool QMetaMethod::isValid ( ) const

Returns true if this QMetaMethod is valid and has a meta object, otherwise returns false.

See also
getMetaObject()
int QMetaMethod::methodIndex ( ) const

Returns an index value for this QMetaMethod object.

const QString & QMetaMethod::methodSignature ( ) const

Returns the signature of this QMetaMethod object.

See also
parameterTypes(), parameterNames()
MethodType QMetaMethod::methodType ( ) const

Returns the type of this QMetaMethod object which is either signal, slot, or method.

See also
access()
const QString QMetaMethod::name ( ) const

Returns the name contained in this QMetaMethod object.

See also
methodSignature(), parameterCount()
int QMetaMethod::parameterCount ( ) const

Returns the number of parameters in this QMetaMethod object.

See also
parameterType(), parameterNames()
QList< QString > QMetaMethod::parameterNames ( ) const

Returns a list of parameter names for this QMetaMethod object.

See also
parameterTypes(), methodSignature()
uint QMetaMethod::parameterType ( int  index) const

The value for index represents which parameter in this QMetaMethod object is being queried. This method returns the data type of the indexed parameter based on the enum in QVariant.

For example, if the data type for the parameter is a bool then the value QVariant::Bool is returned. If no valid type is found QVariant::Invalid will be returned.

See also
parameterCount(), methodType()
QList< QString > QMetaMethod::parameterTypes ( ) const

Returns a list of parameter types for this QMetaMethod object.

See also
parameterNames(), methodSignature()
int QMetaMethod::revision ( ) const

Returns this QMetaMethod object revision number if one was specified by Q_REVISION, otherwise returns 0.

const QString & QMetaMethod::tag ( ) const

Returns the tag associated with this QMetaMethod object. Tags are special macros which make it possible to add extra information about a method. Tag information can be passed as shown in the following example.

private:
CS_SLOT_1(Private, void testFunc())
CS_SLOT_2(testFunc)
CS_TAG("THIS-IS-TEST-TAG", testFunc());

and the information can be accessed by using:

MainWindow win;
win.show();
int functionIndex = win.metaObject()->indexOfSlot("testFunc()");
QMetaMethod mm = metaObject()->method(functionIndex);
qDebug() << mm.tag(); // prints THIS-IS-TEST-TAG
const QString & QMetaMethod::typeName ( ) const

Returns the return data type of this QMetaMethod object.

Friends And Related Function Documentation

bool operator!= ( const QMetaMethod &  method1,
const QMetaMethod &  method2 
)
friend

Returns true if method1 is not equal to method2, otherwise returns false.

bool operator== ( const QMetaMethod &  method1,
const QMetaMethod &  method2 
)
friend

Returns true if method1 is equal to method2, otherwise returns false.