![]() |
Qt 6.x
The Qt SDK
|
\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 | operator== (const QMetaMethod &m1, const QMetaMethod &m2) noexcept |
bool | operator!= (const QMetaMethod &m1, const QMetaMethod &m2) 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.
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 17 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 35 of file qmetaobject.h.
\value Compatibility \value Cloned \value Scriptable
Enumerator | |
---|---|
Compatibility | |
Cloned | |
Scriptable |
Definition at line 39 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 37 of file qmetaobject.h.
|
inlineconstexpr |
Definition at line 20 of file qmetaobject.h.
QMetaMethod::Access QMetaMethod::access | ( | ) | const |
Returns the access specification of this method (private, protected, or public).
Definition at line 2329 of file qmetaobject.cpp.
References AccessMask, mobj, and Private.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), generateInterfaceXml(), and isValidSlot().
int QMetaMethod::attributes | ( | ) | const |
Definition at line 2252 of file qmetaobject.cpp.
References mobj.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), generateInterfaceXml(), and QQmlPropertyCache::originalClone().
|
inline |
Definition at line 46 of file qmetaobject.h.
Referenced by QDBusAdaptorConnector::relay().
|
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 212 of file qmetaobject.h.
References signal.
Referenced by QQuickPixmapReply::QQuickPixmapReply(), QSignalSpy::QSignalSpy(), areaEnteredSignal(), areaExitedSignal(), QTreeView::collapseAll(), QDBusConnectionInterface::connectNotify(), QFutureWatcherBase::connectNotify(), QDBusAbstractInterface::connectNotify(), QMediaDevices::connectNotify(), QDBusConnectionInterface::disconnectNotify(), QFutureWatcherBase::disconnectNotify(), QQuickWindowPrivate::emitError(), QTreeView::expandToDepth(), QQuickWidgetPrivate::handleContextCreationFailure(), is_tracked_signal(), QQuick3DNodePrivate::isDirectionRelatedSignal(), QQuickAbstractButtonPrivate::isDoubleClickConnected(), QQuickAbstractButtonPrivate::isPressAndHoldConnected(), QQuick3DNodePrivate::isSceneTransformRelatedSignal(), monitorExpiredSignal(), QQuickPixmapReader::run(), QWidgetTextControlPrivate::setContent(), QQuickRectangle::setGradient(), and wrapInFunction().
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 2158 of file qmetaobject.cpp.
References mobj.
|
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 QMetaMethodReturnArgument 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. QMetaMethodReturnArgument 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 180 of file qmetaobject.h.
References arguments, and Qt::AutoConnection.
|
inline |
Definition at line 169 of file qmetaobject.h.
References arguments, and Qt::AutoConnection.
|
inline |
Definition at line 158 of file qmetaobject.h.
References arguments.
|
inline |
Definition at line 144 of file qmetaobject.h.
References arguments, and QtPrivate::invokeMethodHelper().
|
inline |
Definition at line 94 of file qmetaobject.h.
References Qt::AutoConnection.
|
inline |
Definition at line 62 of file qmetaobject.h.
References Qt::AutoConnection.
|
inline |
Definition at line 78 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 2491 of file qmetaobject.cpp.
References MaximumParamCount, mobj, and qstrlen().
Referenced by QQuickItem::contains(), QTest::TestMethods::invokeTests(), AVFCameraRenderer::syncHandleViewfinderFrame(), QQuick3DTexture::updateSpatialNode(), and wrapInFunction().
|
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 QMetaMethodReturnArgument 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. QMetaMethodReturnArgument is an internal type you should not use directly. Instead, use the qReturnArg() function.
Definition at line 204 of file qmetaobject.h.
References arguments.
|
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 121 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 2868 of file qmetaobject.cpp.
References QMetaObject::d, QMetaType::fromName(), QMetaObjectPrivate::get(), QMetaObject::InvokeMetaMethod, MaximumParamCount, mobj, QMetaObject::normalizedType(), parameterCount(), Q_ASSERT, qstrcmp(), qstrlen(), returnType(), revision(), QMetaObject::Data::static_metacall, typeName(), and QMetaType::UnknownType.
|
inline |
Definition at line 191 of file qmetaobject.h.
References arguments, and QtPrivate::invokeMethodHelper().
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 2310 of file qmetaobject.cpp.
References QMetaObjectPrivate::get(), MethodIsConst, mobj, and revision().
|
inline |
Returns true
if this method is valid (can be introspected and invoked), otherwise returns false
.
Definition at line 209 of file qmetaobject.h.
Referenced by QQuick3DTexture::QQuick3DTexture(), QMetaObjectPrivate::connect(), QV4::QQmlValueTypeWrapper::dataForPropertyKey(), QMetaObjectPrivate::disconnect(), QTest::TestMethods::invokeTests(), QTest::qSignalDumperCallback(), QTest::qSignalDumperCallbackSlot(), QQuick3DCustomMaterial::updateSpatialNode(), and QQuick3DEffect::updateSpatialNode().
int QMetaMethod::methodIndex | ( | ) | const |
Returns this method's index.
Definition at line 2264 of file qmetaobject.cpp.
References QMetaObject::methodOffset(), and mobj.
Referenced by QQuickPixmapReply::QQuickPixmapReply(), QSignalSpy::QSignalSpy(), QQmlBinding::dependencies(), hasValidSignal(), QQuickPixmapReader::run(), QObject::senderSignalIndex(), QWidgetTextControlPrivate::setContent(), and QQuickRectangle::setGradient().
QByteArray QMetaMethod::methodSignature | ( | ) | const |
Returns the signature of this method (e.g., {setValue(double)}).
Definition at line 2041 of file qmetaobject.cpp.
References mobj.
Referenced by QSignalSpy::QSignalSpy(), QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QQmlProperty::connectNotifySignal(), QObject::dumpObjectInfo(), QMetaObjectPrivate::indexOfSignalRelative(), QQmlVMEMetaObject::metaCall(), QTest::qPrintDataTags(), QTest::qPrintTestSlots(), QTest::qSignalDumperCallbackSlot(), QDBusAdaptorConnector::relay(), QDBusAbstractAdaptor::setAutoRelaySignals(), and QQmlBindEntry::setTarget().
QMetaMethod::MethodType QMetaMethod::methodType | ( | ) | const |
Returns the type of this method (signal, slot, or method).
Definition at line 2341 of file qmetaobject.cpp.
References Method, MethodTypeMask, and mobj.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), QDBusAbstractInterfacePrivate::finishDisconnectNotify(), generateInterfaceXml(), isValidSlot(), QMetaObjectPrivate::memberIndexes(), QDBusInterfacePrivate::metacall(), parameterMetaType(), returnMetaType(), and QDBusAbstractAdaptor::setAutoRelaySignals().
QByteArray QMetaMethod::name | ( | ) | const |
Returns the name of this method.
Definition at line 2055 of file qmetaobject.cpp.
References mobj.
Referenced by QDBusAbstractInterface::callWithArgumentList(), findSlot(), generateInterfaceXml(), isValidSlot(), QDBusInterfacePrivate::metacall(), and QTest::qSignalDumperCallback().
int QMetaMethod::parameterCount | ( | ) | const |
Returns the number of parameters of this method.
Definition at line 2101 of file qmetaobject.cpp.
References mobj.
Referenced by QQmlBoundSignalExpression::evaluate(), fromMatchingType(), fromString(), fromVerifiedType(), invokeOnGadget(), isValidSlot(), and parameterTypeName().
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 2133 of file qmetaobject.cpp.
References Constructor, QMetaObject::d, QMetaObject::Data::metaTypes, methodType(), mobj, parameterType(), priv(), and QMetaType::UnknownType.
Referenced by QQmlBoundSignalExpression::evaluate(), fromMatchingType(), fromString(), and parameterType().
QList< QByteArray > QMetaMethod::parameterNames | ( | ) | const |
Returns a list of parameter names.
Definition at line 2196 of file qmetaobject.cpp.
References mobj.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), generateInterfaceXml(), and QQmlBoundSignal_callback().
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 2118 of file qmetaobject.cpp.
References QMetaType::id(), and parameterMetaType().
Referenced by parameterMetaType().
QByteArray QMetaMethod::parameterTypeName | ( | int | index | ) | const |
Definition at line 2184 of file qmetaobject.cpp.
References mobj, and parameterCount().
QList< QByteArray > QMetaMethod::parameterTypes | ( | ) | const |
Returns a list of parameter types.
Definition at line 2170 of file qmetaobject.cpp.
References mobj.
Referenced by qDBusParametersForMethod(), and QTest::qSignalDumperCallback().
int QMetaMethod::relativeMethodIndex | ( | ) | const |
Returns this method's local index inside.
Definition at line 2276 of file qmetaobject.cpp.
References mobj.
Referenced by QMetaObjectPrivate::memberIndexes().
QMetaType QMetaMethod::returnMetaType | ( | ) | const |
Returns the return type of this method.
Definition at line 2083 of file qmetaobject.cpp.
References Constructor, QMetaObject::d, QMetaObject::Data::metaTypes, methodType(), mobj, returnType(), and QMetaType::UnknownType.
Referenced by findSlot(), generateInterfaceXml(), QQmlMetaObject::methodReturnType(), and returnType().
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 2072 of file qmetaobject.cpp.
References QMetaType::id(), and returnMetaType().
Referenced by invokeOnGadget(), isValidSlot(), QDBusInterfacePrivate::metacall(), and returnMetaType().
int QMetaMethod::revision | ( | ) | const |
Definition at line 2289 of file qmetaobject.cpp.
References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::methodCount, QMetaObjectPrivate::methodData, MethodRevisioned, mobj, priv(), and QMetaMethod::Data::Size.
Referenced by QMetaObjectBuilder::addMethod(), invokeOnGadget(), isConst(), and main().
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 2241 of file qmetaobject.cpp.
References mobj.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QDBusAbstractInterface::callWithArgumentList(), findSlot(), generateInterfaceXml(), and wrapInFunction().
const char * QMetaMethod::typeName | ( | ) | const |
Returns the return type name of this method.
Definition at line 2209 of file qmetaobject.cpp.
References mobj.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), invokeOnGadget(), and QQmlMetaObject::methodReturnType().
|
friend |
Returns true
if method m1 is not equal to method m2, otherwise returns false
.
Definition at line 256 of file qmetaobject.h.
|
friend |
Returns true
if method m1 is equal to method m2, otherwise returns false
.
Definition at line 254 of file qmetaobject.h.
|
friend |
Definition at line 251 of file qmetaobject.h.
|
friend |
Definition at line 252 of file qmetaobject.h.
|
friend |
Definition at line 253 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 1853 of file qmetaobject.cpp.
References QList< T >::at(), QMetaObject::d, QMetaObject::Data::data, i, priv(), Q_ASSERT, QMetaObjectPrivate::revision, and QList< T >::size().
|
protected |
Definition at line 250 of file qmetaobject.h.
|
protected |
Definition at line 249 of file qmetaobject.h.
Referenced by access(), attributes(), getParameterTypes(), invoke(), invokeOnGadget(), isConst(), QMetaObjectPrivate::memberIndexes(), methodIndex(), methodSignature(), methodType(), name(), parameterCount(), parameterMetaType(), parameterNames(), parameterTypeName(), parameterTypes(), relativeMethodIndex(), returnMetaType(), revision(), tag(), and typeName().