Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
\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 36 of file qmetaobject.h.
\value Compatibility \value Cloned \value Scriptable
Enumerator | |
---|---|
Compatibility | |
Cloned | |
Scriptable |
Definition at line 40 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 38 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 2370 of file qmetaobject.cpp.
References AccessMask, and Private.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), and generateInterfaceXml().
int QMetaMethod::attributes | ( | ) | const |
Definition at line 2293 of file qmetaobject.cpp.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), and generateInterfaceXml().
|
inline |
Definition at line 47 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 {nullptr} or not a signal of the class.
Example:
Definition at line 213 of file qmetaobject.h.
References signal.
Referenced by QQuickPixmapReply::QQuickPixmapReply(), 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 2200 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 181 of file qmetaobject.h.
References arguments, and Qt::AutoConnection.
|
inline |
Definition at line 159 of file qmetaobject.h.
References arguments.
|
inline |
Definition at line 145 of file qmetaobject.h.
References arguments, and QtPrivate::invokeMethodHelper().
|
inline |
Definition at line 170 of file qmetaobject.h.
References arguments, and Qt::AutoConnection.
|
inline |
Definition at line 95 of file qmetaobject.h.
References Qt::AutoConnection.
|
inline |
Definition at line 63 of file qmetaobject.h.
References Qt::AutoConnection.
|
inline |
Definition at line 79 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 2533 of file qmetaobject.cpp.
References MaximumParamCount, and qstrlen().
Referenced by QTextDocument::loadResource(), 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 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 205 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 122 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 2910 of file qmetaobject.cpp.
References QMetaObject::d, QMetaType::fromName(), QMetaObjectPrivate::get(), QMetaObject::InvokeMetaMethod, MaximumParamCount, QMetaObject::normalizedType(), Q_ASSERT, qstrcmp(), qstrlen(), typeName, and QMetaType::UnknownType.
|
inline |
Definition at line 192 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 2351 of file qmetaobject.cpp.
References QMetaObjectPrivate::get(), and MethodIsConst.
|
inline |
Returns true
if this method is valid (can be introspected and invoked), otherwise returns false
.
Definition at line 210 of file qmetaobject.h.
Referenced by QQuick3DTexture::QQuick3DTexture(), QV4::QQmlValueTypeWrapper::dataForPropertyKey(), QTest::qSignalDumperCallback(), and QTest::qSignalDumperCallbackSlot().
int QMetaMethod::methodIndex | ( | ) | const |
Returns this method's index.
Definition at line 2305 of file qmetaobject.cpp.
References QMetaObject::methodOffset().
QByteArray QMetaMethod::methodSignature | ( | ) | const |
Returns the signature of this method (e.g., {setValue(double)}).
Definition at line 2083 of file qmetaobject.cpp.
References QByteArray().
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QQmlProperty::connectNotifySignal(), QObject::dumpObjectInfo(), QQmlVMEMetaObject::metaCall(), QTest::qPrintDataTags(), QTest::qSignalDumperCallbackSlot(), QDBusAdaptorConnector::relay(), and QDBusAbstractAdaptor::setAutoRelaySignals().
QMetaMethod::MethodType QMetaMethod::methodType | ( | ) | const |
Returns the type of this method (signal, slot, or method).
Definition at line 2382 of file qmetaobject.cpp.
References Method, and MethodTypeMask.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), findSlot(), QDBusAbstractInterfacePrivate::finishDisconnectNotify(), generateInterfaceXml(), QMetaObjectPrivate::memberIndexes(), QDBusInterfacePrivate::metacall(), and QDBusAbstractAdaptor::setAutoRelaySignals().
QByteArray QMetaMethod::name | ( | ) | const |
Returns the name of this method.
Definition at line 2097 of file qmetaobject.cpp.
References QByteArray().
Referenced by QDBusAbstractInterface::callWithArgumentList(), findSlot(), generateInterfaceXml(), QDBusInterfacePrivate::metacall(), and QTest::qSignalDumperCallback().
int QMetaMethod::parameterCount | ( | ) | const |
Returns the number of parameters of this method.
Definition at line 2143 of file qmetaobject.cpp.
Referenced by QQmlBoundSignalExpression::evaluate(), and qDBusParametersForMethod().
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 2175 of file qmetaobject.cpp.
References Constructor, QMetaObject::d, priv(), and QMetaType::UnknownType.
Referenced by QQmlBoundSignalExpression::evaluate(), and qDBusParametersForMethod().
QList< QByteArray > QMetaMethod::parameterNames | ( | ) | const |
Returns a list of parameter names.
Definition at line 2238 of file qmetaobject.cpp.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), and generateInterfaceXml().
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 2160 of file qmetaobject.cpp.
QByteArray QMetaMethod::parameterTypeName | ( | int | index | ) | const |
Definition at line 2226 of file qmetaobject.cpp.
Referenced by qDBusParametersForMethod().
QList< QByteArray > QMetaMethod::parameterTypes | ( | ) | const |
Returns a list of parameter types.
Definition at line 2212 of file qmetaobject.cpp.
Referenced by QTest::qSignalDumperCallback().
int QMetaMethod::relativeMethodIndex | ( | ) | const |
Returns this method's local index inside.
Definition at line 2317 of file qmetaobject.cpp.
Referenced by QMetaObjectPrivate::memberIndexes().
QMetaType QMetaMethod::returnMetaType | ( | ) | const |
Returns the return type of this method.
Definition at line 2125 of file qmetaobject.cpp.
References Constructor, QMetaObject::d, and QMetaType::UnknownType.
Referenced by findSlot(), generateInterfaceXml(), and QQmlMetaObject::methodReturnType().
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 2114 of file qmetaobject.cpp.
Referenced by QDBusInterfacePrivate::metacall().
int QMetaMethod::revision | ( | ) | const |
Definition at line 2330 of file qmetaobject.cpp.
References QMetaObject::d, MethodRevisioned, and priv().
Referenced by QMetaObjectBuilder::addMethod().
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 2282 of file qmetaobject.cpp.
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 2251 of file qmetaobject.cpp.
Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), and QQmlMetaObject::methodReturnType().
|
friend |
Definition at line 257 of file qmetaobject.h.
|
friend |
Definition at line 252 of file qmetaobject.h.
|
friend |
Definition at line 253 of file qmetaobject.h.
|
friend |
Definition at line 254 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 1893 of file qmetaobject.cpp.
References QMetaObject::d, i, priv(), and Q_ASSERT.
|
protected |
Definition at line 251 of file qmetaobject.h.
|
protected |
Definition at line 250 of file qmetaobject.h.
Referenced by QMetaObjectPrivate::memberIndexes().