![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qmetaobject.h>
Classes | |
struct | Data |
Public Types | |
enum | Access { Private , Protected , Public } |
This enum describes the access level of a method, following the conventions used in C++. More... | |
enum | MethodType { Method , Signal , Slot , Constructor } |
\value Method The function is a plain member function. More... | |
enum | Attributes { Compatibility = 0x1 , Cloned = 0x2 , Scriptable = 0x4 } |
Static Public Member Functions | |
template<typename PointerToMemberFunction> | |
static QMetaMethod | fromSignal (PointerToMemberFunction signal) |
Protected Attributes | |
const QMetaObject * | mobj |
Data | data |
Friends | |
struct | QMetaObject |
struct | QMetaObjectPrivate |
class | QObject |
bool | comparesEqual (const QMetaMethod &lhs, const QMetaMethod &rhs) noexcept |
Related Symbols | |
(Note that these are not member symbols.) | |
QByteArray | signature () const |
\macro Q_METAMETHOD_INVOKE_MAX_ARGS | |
\inmodule QtCore
The QMetaMethod class provides meta-data about a member function.
\compares equality
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 18 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 37 of file qmetaobject.h.
\value Compatibility \value Cloned \value Scriptable
Enumerator | |
---|---|
Compatibility | |
Cloned | |
Scriptable |
Definition at line 41 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 39 of file qmetaobject.h.
|
inlineconstexpr |
Definition at line 21 of file qmetaobject.h.
QMetaMethod::Access QMetaMethod::access | ( | ) | const |
Returns the access specification of this method (private, protected, or public).
Definition at line 2416 of file qmetaobject.cpp.
int QMetaMethod::attributes | ( | ) | const |
Definition at line 2332 of file qmetaobject.cpp.
|
inline |
Definition at line 48 of file qmetaobject.h.
|
inlinestatic |
Returns the meta-method that corresponds to the given signal, or an invalid QMetaMethod if signal is {nullptr} or not a signal of the class.
Example:
Definition at line 214 of file qmetaobject.h.
void QMetaMethod::getParameterTypes | ( | int * | types | ) | const |
Gets the parameter types of this method. The storage for types must be able to hold parameterCount() items.
Definition at line 2230 of file qmetaobject.cpp.
|
inline |
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.
For the overloads with a QTemplatedMetaMethodReturnArgument parameter, the return value of the member function call is placed in ret. For the overloads without such a member, the return value of the called function (if any) will be discarded. QTemplatedMetaMethodReturnArgument is an internal type you should not use directly. Instead, use the qReturnArg() function.
The overloads with a Qt::ConnectionType type parameter allow explicitly selecting whether the invocation will be synchronous or not:
\list
To asynchronously invoke the \l{QPushButton::animateClick()}{animateClick()} slot on a QPushButton:
With asynchronous method invocations, the parameters must be copyable types, because Qt needs to copy the arguments to store them in an event behind the scenes. Since Qt 6.5, this function automatically registers the types being used; however, as a side-effect, it is not possible to make calls using types that are only forward-declared. Additionally, it is not possible to make asynchronous calls that use references to non-const-qualified types as parameters either.
To synchronously invoke the compute(QString, int, double)
slot on some arbitrary object obj
retrieve its return value:
If the "compute" slot does not take exactly one \l QString, one int
, and one double
in the specified order, the call will fail. Note how it was necessary to be explicit about the type of the QString, as the character literal is not exactly the right type to match. If the method instead took a \l QByteArray, a \l qint64, and a {long double}, the call would need to be written as:
The same call can be executed using the Q_ARG() and Q_RETURN_ARG() macros, as in:
Definition at line 182 of file qmetaobject.h.
|
inline |
Definition at line 160 of file qmetaobject.h.
|
inline |
Definition at line 146 of file qmetaobject.h.
|
inline |
Definition at line 171 of file qmetaobject.h.
|
inline |
Definition at line 96 of file qmetaobject.h.
|
inline |
Definition at line 64 of file qmetaobject.h.
|
inline |
Definition at line 80 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 |
\obsolete [6.5] Please use the variadic overload of this function
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.
See the variadic invokeMethod() function for more information. This function should behave the same way as that one, with the following limitations:
\list
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().
Definition at line 2579 of file qmetaobject.cpp.
|
inline |
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.
For the overload with a QTemplatedMetaMethodReturnArgument parameter, the return value of the member function call is placed in ret. For the overload without it, the return value of the called function (if any) will be discarded. QTemplatedMetaMethodReturnArgument is an internal type you should not use directly. Instead, use the qReturnArg() function.
Definition at line 206 of file qmetaobject.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. \obsolete [6.5] Please use the variadic overload of this function.
This overload invokes this method for a gadget and ignores return values.
Definition at line 123 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.
See the variadic invokeMethod() function for more information. This function should behave the same way as that one, with the following limitations:
\list
Definition at line 2956 of file qmetaobject.cpp.
|
inline |
Definition at line 193 of file qmetaobject.h.
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 2397 of file qmetaobject.cpp.
|
inline |
Returns true
if this method is valid (can be introspected and invoked), otherwise returns false
.
Definition at line 211 of file qmetaobject.h.
int QMetaMethod::methodIndex | ( | ) | const |
QByteArray QMetaMethod::methodSignature | ( | ) | const |
Returns the signature of this method (e.g., {setValue(double)}).
Definition at line 2098 of file qmetaobject.cpp.
QMetaMethod::MethodType QMetaMethod::methodType | ( | ) | const |
Returns the type of this method (signal, slot, or method).
Definition at line 2428 of file qmetaobject.cpp.
QByteArray QMetaMethod::name | ( | ) | const |
Returns the name of this method.
Definition at line 2112 of file qmetaobject.cpp.
QByteArrayView QMetaMethod::nameView | ( | ) | const |
Returns the name of this method. The returned QByteArrayView is valid as long as the meta-object of the class to which the method belongs is valid.
Definition at line 2129 of file qmetaobject.cpp.
int QMetaMethod::parameterCount | ( | ) | const |
Returns the number of parameters of this method.
Definition at line 2173 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 2205 of file qmetaobject.cpp.
QList< QByteArray > QMetaMethod::parameterNames | ( | ) | const |
Returns a list of parameter names.
Definition at line 2269 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 2190 of file qmetaobject.cpp.
QByteArray QMetaMethod::parameterTypeName | ( | int | index | ) | const |
Definition at line 2256 of file qmetaobject.cpp.
QList< QByteArray > QMetaMethod::parameterTypes | ( | ) | const |
Returns a list of parameter types.
Definition at line 2242 of file qmetaobject.cpp.
int QMetaMethod::relativeMethodIndex | ( | ) | const |
QMetaType QMetaMethod::returnMetaType | ( | ) | const |
Returns the return type of this method.
Definition at line 2155 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 2144 of file qmetaobject.cpp.
int QMetaMethod::revision | ( | ) | const |
Definition at line 2370 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. Definition at line 2321 of file qmetaobject.cpp.
const char * QMetaMethod::typeName | ( | ) | const |
Returns the return type name of this method.
If this method is a constructor, this function returns an empty string (constructors have no return types).
Definition at line 2286 of file qmetaobject.cpp.
|
friend |
Definition at line 258 of file qmetaobject.h.
|
friend |
Definition at line 253 of file qmetaobject.h.
|
friend |
Definition at line 254 of file qmetaobject.h.
|
friend |
Definition at line 255 of file qmetaobject.h.
|
\macro Q_METAMETHOD_INVOKE_MAX_ARGS
Equals maximum number of arguments available for execution of the method via QMetaMethod::invoke()
Definition at line 1905 of file qmetaobject.cpp.
|
protected |
Definition at line 252 of file qmetaobject.h.
|
protected |
Definition at line 251 of file qmetaobject.h.