Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions |
The QMetaMethod class provides meta-data about a member function. More...
#include <QMetaMethod>
The QMetaMethod class provides meta-data about a member function.
A QMetaMethod has a methodType(), a signature(), 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, and Qt's Property System.
This enum describes the access level of a method, following the conventions used in C++.
Constant | Value |
---|---|
QMetaMethod::Private | 0 |
QMetaMethod::Protected | 1 |
QMetaMethod::Public | 2 |
Constant | Value | Description |
---|---|---|
QMetaMethod::Method | 0 | The function is a plain member function. |
QMetaMethod::Signal | 1 | The function is a signal. |
QMetaMethod::Slot | 2 | The function is a slot. |
QMetaMethod::Constructor | 3 | The function is a constructor. |
Returns the access specification of this method (private, protected, or public).
Signals are always protected, meaning that you can only emit them from the class or from a subclass.
See also methodType().
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:
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 animateClick() slot on a QPushButton:
int methodIndex = pushButton->metaObject()->indexOfMethod("animateClick()"); QMetaMethod method = metaObject->method(methodIndex); method.invoke(pushButton, Qt::QueuedConnection);
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
QMetaMethod::invoke: Unable to handle unregistered datatype 'MyType'
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:
QString retVal; QByteArray 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), Q_ARG(QString, "sqrt"), Q_ARG(int, 42), Q_ARG(double, 9.7));
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.
See also Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), and QMetaObject::invokeMethod().
This function overloads invoke().
This overload always invokes this method using the connection type Qt::AutoConnection.
This function overloads invoke().
This overload can be used if the return value of the member is of no interest.
This function overloads invoke().
This overload invokes this method using the connection type Qt::AutoConnection and ignores return values.
Returns the type of this method (signal, slot, or method).
See also access().
Returns a list of parameter names.
See also parameterTypes() and signature().
Returns a list of parameter types.
See also parameterNames() and signature().
Returns the signature of this method (e.g., setValue(double)).
See also parameterTypes() and parameterNames().
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. For the moment, moc doesn't support any special tags.
Returns the return type of this method, or an empty string if the return type is void.
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.5.1 |