QtBase
v6.3.1
|
The QMetaMethod class provides meta-data about a member function. More...
#include <qmetaobject.h>
Public Types | |
enum | Access { Private , Protected , Public } |
enum | MethodType { Method , Signal , Slot , Constructor } |
enum | Attributes { Compatibility = 0x1 , Cloned = 0x2 , Scriptable = 0x4 } |
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 |
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.
Definition at line 53 of file qmetaobject.h.
enum QMetaMethod::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.
Enumerator | |
---|---|
Compatibility | |
Cloned | |
Scriptable |
Definition at line 75 of file qmetaobject.h.
\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.
|
inlineconstexpr |
Definition at line 56 of file qmetaobject.h.
QMetaMethod::Access QMetaMethod::access | ( | ) | const |
Returns the access specification of this method (private, protected, or public).
Definition at line 2176 of file qmetaobject.cpp.
int QMetaMethod::attributes | ( | ) | const |
|
inline |
|
inlinestatic |
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.
void QMetaMethod::getParameterTypes | ( | int * | types | ) | const |
|
inline |
Definition at line 129 of file qmetaobject.h.
|
inline |
Definition at line 97 of file qmetaobject.h.
|
inline |
Definition at line 113 of file qmetaobject.h.
bool QMetaMethod::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 |
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
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.
Definition at line 2295 of file qmetaobject.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This overload invokes this method for a gadget and ignores return values.
Definition at line 156 of file qmetaobject.h.
bool QMetaMethod::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 |
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.
Definition at line 2521 of file qmetaobject.cpp.
bool QMetaMethod::isConst | ( | ) | const |
Returns whether the method is const qualified.
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.
|
inline |
Returns true
if this method is valid (can be introspected and invoked), otherwise returns false
.
Definition at line 172 of file qmetaobject.h.
int QMetaMethod::methodIndex | ( | ) | const |
Returns this method's index.
Definition at line 2111 of file qmetaobject.cpp.
QByteArray QMetaMethod::methodSignature | ( | ) | const |
Returns the signature of this method (e.g., {setValue(double)}).
Definition at line 1888 of file qmetaobject.cpp.
QMetaMethod::MethodType QMetaMethod::methodType | ( | ) | const |
Returns the type of this method (signal, slot, or method).
Definition at line 2188 of file qmetaobject.cpp.
QByteArray QMetaMethod::name | ( | ) | const |
Returns the name of this method.
Definition at line 1902 of file qmetaobject.cpp.
int QMetaMethod::parameterCount | ( | ) | const |
Returns the number of parameters of this method.
Definition at line 1948 of file qmetaobject.cpp.
QMetaType QMetaMethod::parameterMetaType | ( | int | index | ) | const |
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.
Definition at line 1980 of file qmetaobject.cpp.
QList< QByteArray > QMetaMethod::parameterNames | ( | ) | const |
Returns a list of parameter names.
Definition at line 2043 of file qmetaobject.cpp.
int QMetaMethod::parameterType | ( | int | index | ) | const |
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.
Definition at line 1965 of file qmetaobject.cpp.
QByteArray QMetaMethod::parameterTypeName | ( | int | index | ) | const |
Definition at line 2031 of file qmetaobject.cpp.
QList< QByteArray > QMetaMethod::parameterTypes | ( | ) | const |
Returns a list of parameter types.
Definition at line 2017 of file qmetaobject.cpp.
int QMetaMethod::relativeMethodIndex | ( | ) | const |
Returns this method's local index inside.
Definition at line 2123 of file qmetaobject.cpp.
QMetaType QMetaMethod::returnMetaType | ( | ) | const |
Returns the return type of this method.
Definition at line 1930 of file qmetaobject.cpp.
int QMetaMethod::returnType | ( | ) | const |
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.
Definition at line 1919 of file qmetaobject.cpp.
int QMetaMethod::revision | ( | ) | const |
Definition at line 2136 of file qmetaobject.cpp.
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.
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.
const char * QMetaMethod::typeName | ( | ) | const |
Returns the return type name of this method.
Definition at line 2056 of file qmetaobject.cpp.
|
friend |
Returns true
if method m1 is not equal to method m2, otherwise returns false
.
Definition at line 214 of file qmetaobject.h.
|
friend |
Returns true
if method m1 is equal to method m2, otherwise returns false
.
Definition at line 212 of file qmetaobject.h.
|
friend |
Definition at line 208 of file qmetaobject.h.
|
friend |
Definition at line 209 of file qmetaobject.h.
|
friend |
Definition at line 210 of file qmetaobject.h.
|
friend |
Definition at line 211 of file qmetaobject.h.
|
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.