QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QMetaMethod Class Reference

The QMetaMethod class provides meta-data about a member function. More...

#include <qmetaobject.h>

Inheritance diagram for QMetaMethod:
Inheritance graph
[legend]

Public Types

enum  Access { Private , Protected , Public }
 
enum  MethodType { Method , Signal , Slot , Constructor }
 
enum  Attributes { Compatibility = 0x1 , Cloned = 0x2 , Scriptable = 0x4 }
 

Public Member Functions

constexpr QMetaMethod ()
 
QByteArray methodSignature () const
 
QByteArray name () const
 
const char * typeName () const
 
int returnType () const
 
QMetaType returnMetaType () const
 
int parameterCount () const
 
int parameterType (int index) const
 
QMetaType parameterMetaType (int index) const
 
void getParameterTypes (int *types) const
 
QList< QByteArrayparameterTypes () const
 
QByteArray parameterTypeName (int index) const
 
QList< QByteArrayparameterNames () const
 
const char * tag () const
 
Access access () const
 
MethodType methodType () const
 
int attributes () const
 
int methodIndex () const
 
int relativeMethodIndex () const
 
int revision () const
 
bool isConst () const
 
const QMetaObjectenclosingMetaObject () const
 
bool invoke (QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invoke (QObject *object, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invoke (QObject *object, Qt::ConnectionType connectionType, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invoke (QObject *object, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invokeOnGadget (void *gadget, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invokeOnGadget (void *gadget, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool isValid () const
 

Static Public Member Functions

template<typename PointerToMemberFunction >
static QMetaMethod fromSignal (PointerToMemberFunction signal)
 

Friends

class QMetaMethodPrivate
 
struct QMetaObject
 
struct QMetaObjectPrivate
 
class QObject
 
bool operator== (const QMetaMethod &m1, const QMetaMethod &m2) noexcept
 
bool operator!= (const QMetaMethod &m1, const QMetaMethod &m2) noexcept
 

Related Functions

(Note that these are not member functions.)

QByteArray signature () const
 

Detailed Description

The QMetaMethod class provides meta-data about a member function.

\inmodule QtCore

A QMetaMethod has a methodType(), a methodSignature(), a list of parameterTypes() and parameterNames(), a return typeName(), a tag(), and an access() specifier. You can use invoke() to invoke the method on an arbitrary QObject.

See also
QMetaObject, QMetaEnum, QMetaProperty, {Qt's Property System}

Definition at line 53 of file qmetaobject.h.

Member Enumeration Documentation

◆ Access

This enum describes the access level of a method, following the conventions used in C++.

\value Private \value Protected \value Public

Enumerator
Private 
Protected 
Public 

Definition at line 71 of file qmetaobject.h.

◆ Attributes

Enumerator
Compatibility 
Cloned 
Scriptable 

Definition at line 75 of file qmetaobject.h.

◆ MethodType

\value Method The function is a plain member function. \value Signal The function is a signal. \value Slot The function is a slot. \value Constructor The function is a constructor.

Enumerator
Method 
Signal 
Slot 
Constructor 

Definition at line 73 of file qmetaobject.h.

Constructor & Destructor Documentation

◆ QMetaMethod()

QMetaMethod::QMetaMethod ( )
inlineconstexpr

Definition at line 56 of file qmetaobject.h.

Member Function Documentation

◆ access()

QMetaMethod::Access QMetaMethod::access ( ) const

Returns the access specification of this method (private, protected, or public).

Note
Signals are always public, but you should regard that as an implementation detail. It is almost always a bad idea to emit a signal from outside its class.
See also
methodType()

Definition at line 2176 of file qmetaobject.cpp.

Here is the caller graph for this function:

◆ attributes()

int QMetaMethod::attributes ( ) const

Definition at line 2099 of file qmetaobject.cpp.

Here is the caller graph for this function:

◆ enclosingMetaObject()

const QMetaObject * QMetaMethod::enclosingMetaObject ( ) const
inline

Definition at line 82 of file qmetaobject.h.

Here is the caller graph for this function:

◆ fromSignal()

template<typename PointerToMemberFunction >
template< typename PointerToMemberFunction > QMetaMethod QMetaMethod::fromSignal ( PointerToMemberFunction  signal)
inlinestatic
Since
5.0

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

Example:

Definition at line 175 of file qmetaobject.h.

Here is the caller graph for this function:

◆ getParameterTypes()

void QMetaMethod::getParameterTypes ( int *  types) const
Since
5.0

Definition at line 2005 of file qmetaobject.cpp.

Here is the call graph for this function:

◆ invoke() [1/4]

Definition at line 129 of file qmetaobject.h.

◆ invoke() [2/4]

Definition at line 97 of file qmetaobject.h.

◆ invoke() [3/4]

Definition at line 113 of file qmetaobject.h.

◆ invoke() [4/4]

Invokes this method on the object object. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.

The invocation can be either synchronous or asynchronous, depending on the connectionType:

\list

  • If connectionType is Qt::QueuedConnection, a QEvent will be posted and the member is invoked as soon as the application enters the main event loop.
  • If connectionType is Qt::AutoConnection, the member is invoked synchronously if object lives in the same thread as the caller; otherwise it will invoke the member asynchronously. \endlist

The return value of this method call is placed in returnValue. If the invocation is asynchronous, the return value cannot be evaluated. You can pass up to ten arguments (val0, val1, val2, val3, val4, val5, val6, val7, val8, and val9) to this method call.

QGenericArgument and QGenericReturnArgument are internal helper classes. Because signals and slots can be dynamically invoked, you must enclose the arguments using the Q_ARG() and Q_RETURN_ARG() macros. Q_ARG() takes a type name and a const reference of that type; Q_RETURN_ARG() takes a type name and a non-const reference.

To asynchronously invoke the \l{QPushButton::animateClick()}{animateClick()} slot on a QPushButton:

With asynchronous method invocations, 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

call qRegisterMetaType() to register the data type before you call QMetaMethod::invoke().

To synchronously invoke the compute(QString, int, double) slot on some arbitrary object obj retrieve its return value:

QMetaObject::normalizedSignature() is used here to ensure that the format of the signature is what invoke() expects. E.g. extra whitespace is removed.

If the "compute" slot does not take exactly one QString, one int and one double in the specified order, the call will fail.

Warning
this method will not test the validity of the arguments: object must be an instance of the class of the QMetaObject of which this QMetaMethod has been constructed with. The arguments must have the same type as the ones expected by the method, else, the behaviour is undefined.
See also
Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod()

Definition at line 2295 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeOnGadget() [1/2]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.5

This overload invokes this method for a gadget and ignores return values.

Definition at line 156 of file qmetaobject.h.

◆ invokeOnGadget() [2/2]

Since
5.5

Invokes this method on a Q_GADGET. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.

The pointer gadget must point to an instance of the gadget class.

The invocation is always synchronous.

The return value of this method call is placed in returnValue. You can pass up to ten arguments (val0, val1, val2, val3, val4, val5, val6, val7, val8, and val9) to this method call.

Warning
this method will not test the validity of the arguments: gadget must be an instance of the class of the QMetaObject of which this QMetaMethod has been constructed with. The arguments must have the same type as the ones expected by the method, else, the behavior is undefined.
See also
Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod()

Definition at line 2521 of file qmetaobject.cpp.

Here is the call graph for this function:

◆ isConst()

bool QMetaMethod::isConst ( ) const
Since
6.2

Returns whether the method is const qualified.

Note
This method might erroneously return false for a const method if it belongs to a library compiled against an older version of Qt.

Definition at line 2157 of file qmetaobject.cpp.

Here is the call graph for this function:

◆ isValid()

bool QMetaMethod::isValid ( ) const
inline
Since
5.0

Returns true if this method is valid (can be introspected and invoked), otherwise returns false.

Definition at line 172 of file qmetaobject.h.

Here is the caller graph for this function:

◆ methodIndex()

int QMetaMethod::methodIndex ( ) const
Since
4.6

Returns this method's index.

Definition at line 2111 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ methodSignature()

QByteArray QMetaMethod::methodSignature ( ) const
Since
5.0

Returns the signature of this method (e.g., {setValue(double)}).

See also
parameterTypes(), parameterNames()

Definition at line 1888 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ methodType()

QMetaMethod::MethodType QMetaMethod::methodType ( ) const

Returns the type of this method (signal, slot, or method).

See also
access()

Definition at line 2188 of file qmetaobject.cpp.

Here is the caller graph for this function:

◆ name()

QByteArray QMetaMethod::name ( ) const
Since
5.0

Returns the name of this method.

See also
methodSignature(), parameterCount()

Definition at line 1902 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parameterCount()

int QMetaMethod::parameterCount ( ) const
Since
5.0

Returns the number of parameters of this method.

See also
parameterType(), parameterNames()

Definition at line 1948 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parameterMetaType()

QMetaType QMetaMethod::parameterMetaType ( int  index) const
Since
6.0

Returns the metatype of the parameter at the given index.

If the index is smaller than zero or larger than parameterCount(), an invalid QMetaType is returned.

See also
parameterCount(), returnMetaType(), QMetaType

Definition at line 1980 of file qmetaobject.cpp.

Here is the caller graph for this function:

◆ parameterNames()

QList< QByteArray > QMetaMethod::parameterNames ( ) const

Returns a list of parameter names.

See also
parameterTypes(), methodSignature()

Definition at line 2043 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parameterType()

int QMetaMethod::parameterType ( int  index) const
Since
5.0

Returns the type of the parameter at the given index.

The return value is one of the types that are registered with QMetaType, or QMetaType::UnknownType if the type is not registered.

See also
parameterCount(), parameterMetaType(), returnType(), QMetaType

Definition at line 1965 of file qmetaobject.cpp.

Here is the call graph for this function:

◆ parameterTypeName()

QByteArray QMetaMethod::parameterTypeName ( int  index) const
Since
6.0 Returns the name of the type at position index If there is no parameter at index, returns an empty QByteArray
See also
parameterNames()

Definition at line 2031 of file qmetaobject.cpp.

Here is the call graph for this function:

◆ parameterTypes()

QList< QByteArray > QMetaMethod::parameterTypes ( ) const

Returns a list of parameter types.

See also
parameterNames(), methodSignature()

Definition at line 2017 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ relativeMethodIndex()

int QMetaMethod::relativeMethodIndex ( ) const
Since
6.0

Returns this method's local index inside.

Definition at line 2123 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ returnMetaType()

QMetaType QMetaMethod::returnMetaType ( ) const
Since
6.0

Returns the return type of this method.

See also
parameterMetaType(), QMetaType, typeName()

Definition at line 1930 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ returnType()

int QMetaMethod::returnType ( ) const
Since
5.0

Returns the return type of this method.

The return value is one of the types that are registered with QMetaType, or QMetaType::UnknownType if the type is not registered.

See also
parameterType(), QMetaType, typeName(), returnMetaType()

Definition at line 1919 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ revision()

int QMetaMethod::revision ( ) const
Since
5.1 Returns the method revision if one was specified by Q_REVISION, otherwise returns 0.

Definition at line 2136 of file qmetaobject.cpp.

Here is the caller graph for this function:

◆ tag()

const char * QMetaMethod::tag ( ) const

Returns the tag associated with this method.

Tags are special macros recognized by moc that make it possible to add extra information about a method.

Tag information can be added in the following way in the function declaration:

and the information can be accessed by using:

For the moment, moc will extract and record all tags, but it will not handle any of them specially. You can use the tags to annotate your methods differently, and treat them according to the specific needs of your application.

Note
Since Qt 5.0, moc expands preprocessor macros, so it is necessary to surround the definition with #ifndef Q_MOC_RUN, as shown in the example above. This was not required in Qt 4. The code as shown above works with Qt 4 too.

Definition at line 2088 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ typeName()

const char * QMetaMethod::typeName ( ) const

Returns the return type name of this method.

See also
returnType(), QMetaType::type()

Definition at line 2056 of file qmetaobject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QMetaMethod::operator!= ( const QMetaMethod m1,
const QMetaMethod m2 
)
friend
Since
5.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if method m1 is not equal to method m2, otherwise returns false.

Definition at line 214 of file qmetaobject.h.

◆ operator==

bool QMetaMethod::operator== ( const QMetaMethod m1,
const QMetaMethod m2 
)
friend
Since
5.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if method m1 is equal to method m2, otherwise returns false.

Definition at line 212 of file qmetaobject.h.

◆ QMetaMethodPrivate

friend class QMetaMethodPrivate
friend

Definition at line 208 of file qmetaobject.h.

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 209 of file qmetaobject.h.

◆ QMetaObjectPrivate

friend struct QMetaObjectPrivate
friend

Definition at line 210 of file qmetaobject.h.

◆ QObject

friend class QObject
friend

Definition at line 211 of file qmetaobject.h.

◆ signature()

QByteArray signature ( ) const
related

\macro Q_METAMETHOD_INVOKE_MAX_ARGS

Equals maximum number of arguments available for execution of the method via QMetaMethod::invoke()

Definition at line 1759 of file qmetaobject.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: