QMetaMethod Class
The QMetaMethod class provides meta-data about a member function. More…
| Header | #include <QMetaMethod> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | Access |
| enum | MethodType |
| enum | Attributes |
Public Functions
Static Public Members
| QMetaMethod | fromSignal(PointerToMemberFunction signal) |
Detailed Description
A QMetaMethod describes a signal, a slot, an invokable method or a constructor that ntmoc found in a class. Get one from QMetaObject::method() or QMetaObject::indexOfMethod(), or for a signal from fromSignal().
const QMetaObject *mo = &QTimer::staticMetaObject;
QMetaMethod m = mo->method(mo->indexOfSlot("start(int)"));
qDebug() << m.methodSignature() << m.parameterCount();
m.invoke(&timer, Q_ARG(int, 100));
See also QMetaObject, QMetaProperty and QMetaEnum.
Differences from Qt
invokeOnGadget() and invoke() take Q_ARG() and Q_RETURN_ARG() arguments only, not plain values and qReturnArg(). Argument types are compared by name, as in Qt, so the types of a queued call must be registered with the meta-type system. A Qt::BlockingQueuedConnection call to an object in the calling thread runs the method directly, where Qt reports a deadlock.
Member Type Documentation
enum QMetaMethod::Access
This enum describes the access level of a method.
| Constant | Description |
|---|---|
QMetaMethod::Private | The method is private. |
QMetaMethod::Protected | The method is protected. |
QMetaMethod::Public | The method is public. |
enum QMetaMethod::Attributes
This enum describes properties of a method, which attributes() combines.
| Constant | Description |
|---|---|
QMetaMethod::Compatibility | The method is a compatibility member; ntmoc never sets it. |
QMetaMethod::Cloned | The method is an overload that default arguments produced. |
QMetaMethod::Scriptable | The method is declared with Q_SCRIPTABLE. |
enum QMetaMethod::MethodType
This enum describes the kind of a method.
| Constant | Description |
|---|---|
QMetaMethod::Method | A function that is declared with Q_INVOKABLE. |
QMetaMethod::Signal | A signal. |
QMetaMethod::Slot | A slot. |
QMetaMethod::Constructor | A constructor that is declared with Q_INVOKABLE. |
Member Function Documentation
QMetaMethod::QMetaMethod()
Constructs an invalid method.
See also isValid().
Access QMetaMethod::access() const
Returns the access level of the method. Signals are public.
See also methodType().
int QMetaMethod::attributes() const
Returns the attributes of the method, a combination of QMetaMethod::Attributes values.
const QMetaObject * QMetaMethod::enclosingMetaObject() const
Returns the meta-object of the class that declares the method.
template <typename PointerToMemberFunction> QMetaMethod QMetaMethod::fromSignal(PointerToMemberFunction signal)
Returns the meta-method of the signal signal, a pointer to a signal of a class that ntmoc processed. Returns an invalid method if the pointer does not name a signal.
See also QMetaObject::indexOfSignal().
void QMetaMethod::getParameterTypes(int *types) const
Stores the QMetaType ids of the parameters in types, which must have room for parameterCount() entries.
See also parameterType().
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 object and returns true if it could be invoked. The arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, made with Q_ARG(), must match the parameters of the method in number and type, and returnValue, made with Q_RETURN_ARG(), receives the return value; its type must match the return type of the method. See QMetaObject::invokeMethod() for connectionType.
Returns false if the method is a constructor, if object is not an instance of the class of the method, or if the arguments do not fit.
See also QMetaObject::invokeMethod().
bool QMetaMethod::invoke(QObject *object, 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
This is an overloaded function.
Invokes the method on object with Qt::AutoConnection, storing the result in returnValue.
bool QMetaMethod::invoke(QObject *object, Qt::ConnectionType connectionType, 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
This is an overloaded function.
Invokes the method on object with the connection type connectionType, discarding the result.
bool QMetaMethod::invoke(QObject *object, 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
This is an overloaded function.
Invokes the method on object with Qt::AutoConnection, discarding the result.
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 gadget, an instance of the Q_GADGET class that declares the method, and returns true if it could be invoked. The arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, made with Q_ARG(), must match the parameters of the method in number and type, and returnValue, made with Q_RETURN_ARG(), receives the return value; its type must match the return type of the method. The call is always direct.
const QMetaObject &mo = Point::staticMetaObject;
Point point{3, 4};
int length = 0;
mo.method(mo.indexOfMethod("manhattanLength()")).invokeOnGadget(&point, Q_RETURN_ARG(int, length));
Returns false if gadget is nullptr, if the method is a constructor, or if the arguments do not fit. The function cannot check that gadget is an instance of the right class; passing anything else is undefined behavior.
This function was introduced in 5.5.
See also invoke() and QMetaProperty::readOnGadget().
bool QMetaMethod::invokeOnGadget(void *gadget, 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
This is an overloaded function.
Invokes the method on gadget with the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, discarding the result.
This function was introduced in 5.5.
bool QMetaMethod::isValid() const
Returns true if this object describes a method; otherwise returns false.
int QMetaMethod::methodIndex() const
Returns the index of the method in its class, counting the methods of the base classes first. For a constructor, returns its index among the constructors.
See also relativeMethodIndex() and QMetaObject::method().
QByteArray QMetaMethod::methodSignature() const
Returns the signature of the method, such as "setValue(int)". Types are normalized.
See also name() and parameterTypes().
MethodType QMetaMethod::methodType() const
Returns the kind of the method.
See also access().
QByteArray QMetaMethod::name() const
Returns the name of the method without its parameters.
See also methodSignature().
QObject * QMetaMethod::newInstance(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
Creates a new instance with this constructor, passing the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, and returns it. Returns nullptr if this is not a constructor or the arguments do not match its parameters in number and type.
See also QMetaObject::newInstance().
int QMetaMethod::parameterCount() const
Returns the number of parameters of the method.
See also parameterTypes() and parameterNames().
QMetaType QMetaMethod::parameterMetaType(int param) const
Returns the QMetaType of the parameter at param, or an invalid QMetaType if param is out of range.
See also parameterType().
QList<QByteArray> QMetaMethod::parameterNames() const
Returns the names of the parameters in order. A parameter that is declared without a name has an empty name.
See also parameterTypes().
int QMetaMethod::parameterType(int param) const
Returns the QMetaType id of the parameter at param, or QMetaType::UnknownType if param is out of range or the type is not known.
See also parameterMetaType().
QList<QByteArray> QMetaMethod::parameterTypes() const
Returns the names of the parameter types, such as "QString", in order.
See also parameterNames().
int QMetaMethod::relativeMethodIndex() const
Returns the index of the method among the methods of its own class, not counting those of the base classes.
See also methodIndex().
QMetaType QMetaMethod::returnMetaType() const
Returns the QMetaType of the return type.
See also returnType().
int QMetaMethod::returnType() const
Returns the QMetaType id of the return type, or QMetaType::UnknownType if it is not known.
See also returnMetaType().
int QMetaMethod::revision() const
Returns the revision of the method, which is 0 unless it is declared with Q_REVISION().
const char * QMetaMethod::tag() const
Returns the tag of the method, which is an empty string unless a tag was set with moc.
const char * QMetaMethod::typeName() const
Returns the name of the return type of the method, "void" for a method that returns nothing, or an empty string for a constructor.
See also returnType().