QMetaMethod¶
The
QMetaMethodclass provides meta-data about a member function. More…

Synopsis¶
Functions¶
def
__eq__(, m2)def
__ne__(, m2)def
access()def
enclosingMetaObject()def
invoke(object, connectionType, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
invoke(object, connectionType[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
invoke(object, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
invoke(object[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
invokeOnGadget(gadget, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
invokeOnGadget(gadget[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])def
isValid()def
methodIndex()def
methodSignature()def
methodType()def
name()def
parameterCount()def
parameterNames()def
parameterType(index)def
parameterTypes()def
returnType()def
revision()def
tag()def
typeName()
Detailed Description¶
A
QMetaMethodhas amethodType(), amethodSignature(), a list ofparameterTypes()andparameterNames(), a returntypeName(), atag(), and anaccess()specifier. You can useinvoke()to invoke the method on an arbitraryQObject.
- class PySide2.QtCore.QMetaMethod¶
PySide2.QtCore.QMetaMethod(QMetaMethod)
- Parameters:
QMetaMethod –
PySide2.QtCore.QMetaMethod
- PySide2.QtCore.QMetaMethod.Access¶
This enum describes the access level of a method, following the conventions used in C++.
Constant
Description
QMetaMethod.Private
QMetaMethod.Protected
QMetaMethod.Public
- PySide2.QtCore.QMetaMethod.MethodType¶
Constant
Description
QMetaMethod.Method
The function is a plain member function.
QMetaMethod.Signal
The function is a signal.
QMetaMethod.Slot
The function is a slot.
QMetaMethod.Constructor
The function is a constructor.
- PySide2.QtCore.QMetaMethod.access()¶
- Return type:
Returns the access specification of this method (private, protected, or public).
Note
Signals are always public, but you should regard that as an implementation detail. It is almost always a bad idea to emit a signal from outside its class.
See also
- PySide2.QtCore.QMetaMethod.enclosingMetaObject()¶
- Return type:
- PySide2.QtCore.QMetaMethod.invoke(object[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])¶
- Parameters:
object –
PySide2.QtCore.QObject
- Return type:
bool
This function overloads
invoke().This overload invokes this method using the connection type
AutoConnectionand ignores return values.
- PySide2.QtCore.QMetaMethod.invoke(object, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
object –
PySide2.QtCore.QObjectreturnValue –
PySide2.QtCore.QGenericReturnArgument
- Return type:
bool
This function overloads
invoke().This overload always invokes this method using the connection type
AutoConnection.
- PySide2.QtCore.QMetaMethod.invoke(object, connectionType[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
object –
PySide2.QtCore.QObjectconnectionType –
ConnectionType
- Return type:
bool
This function overloads
invoke().This overload can be used if the return value of the member is of no interest.
- PySide2.QtCore.QMetaMethod.invoke(object, connectionType, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
object –
PySide2.QtCore.QObjectconnectionType –
ConnectionTypereturnValue –
PySide2.QtCore.QGenericReturnArgument
- Return type:
bool
Invokes this method on the object
object. Returnstrueif the member could be invoked. Returnsfalseif there is no such member or the parameters did not match.The invocation can be either synchronous or asynchronous, depending on the
connectionType:If
connectionTypeisDirectConnection, the member will be invoked immediately.If
connectionTypeisQueuedConnection, aQEventwill be posted and the member is invoked as soon as the application enters the main event loop.If
connectionTypeisAutoConnection, the member is invoked synchronously ifobjectlives in the same thread as the caller; otherwise it will invoke the member asynchronously.
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, andval9) to this method call.QGenericArgumentandQGenericReturnArgumentare internal helper classes. Because signals and slots can be dynamically invoked, you must enclose the arguments using theQ_ARG()andQ_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
animateClick()slot on aQPushButton:methodIndex = pushButton.metaObject().indexOfMethod("animateClick()") method = metaObject.method(methodIndex) method.invoke(pushButton, Qt.QueuedConnection)
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
QMetaMethod.invoke: Unable to handle unregistered datatype 'MyType'
call
qRegisterMetaType()to register the data type before you call .To synchronously invoke the
compute(QString, int, double)slot on some arbitrary objectobjretrieve its return value:retVal = QString() normalizedSignature = QMetaObject.normalizedSignature("compute(QString, int, double)") methodIndex = obj.metaObject().indexOfMethod(normalizedSignature) method = metaObject.method(methodIndex) method.invoke(obj, Qt.DirectConnection, Q_RETURN_ARG(QString, retVal), Q_ARG(QString, "sqrt"), Q_ARG(int, 42), Q_ARG(double, 9.7));
normalizedSignature()is used here to ensure that the format of the signature is what 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.Warning
this method will not test the validity of the arguments:
objectmust be an instance of the class of theQMetaObjectof which thisQMetaMethodhas been constructed with. The arguments must have the same type as the ones expected by the method, else, the behaviour is undefined.See also
Q_ARG()Q_RETURN_ARG()qRegisterMetaType()invokeMethod()
- PySide2.QtCore.QMetaMethod.invokeOnGadget(gadget[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])¶
- Parameters:
gadget –
void
- Return type:
bool
This is an overloaded function.
This overload invokes this method for a
gadgetand ignores return values.
- PySide2.QtCore.QMetaMethod.invokeOnGadget(gadget, returnValue[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
gadget –
voidreturnValue –
PySide2.QtCore.QGenericReturnArgument
- Return type:
bool
Invokes this method on a
Q_GADGET. Returnstrueif the member could be invoked. Returnsfalseif there is no such member or the parameters did not match.The pointer
gadgetmust 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, andval9) to this method call.Warning
this method will not test the validity of the arguments:
gadgetmust be an instance of the class of theQMetaObjectof which thisQMetaMethodhas been constructed with. The arguments must have the same type as the ones expected by the method, else, the behavior is undefined.See also
Q_ARG()Q_RETURN_ARG()qRegisterMetaType()invokeMethod()
- PySide2.QtCore.QMetaMethod.isValid()¶
- Return type:
bool
Returns
trueif this method is valid (can be introspected and invoked), otherwise returnsfalse.
- PySide2.QtCore.QMetaMethod.methodIndex()¶
- Return type:
int
Returns this method’s index.
- PySide2.QtCore.QMetaMethod.methodSignature()¶
- Return type:
Returns the signature of this method (e.g.,
setValue(double)).See also
- PySide2.QtCore.QMetaMethod.methodType()¶
- Return type:
Returns the type of this method (signal, slot, or method).
See also
- PySide2.QtCore.QMetaMethod.name()¶
- Return type:
Returns the name of this method.
See also
- PySide2.QtCore.QMetaMethod.__ne__(m2)¶
- Parameters:
- Return type:
bool
- PySide2.QtCore.QMetaMethod.__eq__(m2)¶
- Parameters:
- Return type:
bool
- PySide2.QtCore.QMetaMethod.parameterCount()¶
- Return type:
int
Returns the number of parameters of this method.
See also
- PySide2.QtCore.QMetaMethod.parameterNames()¶
- Return type:
Returns a list of parameter names.
See also
- PySide2.QtCore.QMetaMethod.parameterType(index)¶
- Parameters:
index – int
- Return type:
int
Returns the type of the parameter at the given
index.The return value is one of the types that are registered with
QMetaType, orUnknownTypeif the type is not registered.See also
parameterCount()returnType()QMetaType
- PySide2.QtCore.QMetaMethod.parameterTypes()¶
- Return type:
Returns a list of parameter types.
See also
- PySide2.QtCore.QMetaMethod.returnType()¶
- Return type:
int
Returns the return type of this method.
The return value is one of the types that are registered with
QMetaType, orUnknownTypeif the type is not registered.See also
parameterType()QMetaTypetypeName()
- PySide2.QtCore.QMetaMethod.revision()¶
- Return type:
int
Returns the method revision if one was specified by
Q_REVISION, otherwise returns 0.
- PySide2.QtCore.QMetaMethod.tag()¶
- Return type:
str
Returns the tag associated with this method.
Tags are special macros recognized by
mocthat make it possible to add extra information about a method.Tag information can be added in the following way in the function declaration:
// In the class MainWindow declaration #ifndef Q_MOC_RUN // define the tag text as empty, so the compiler doesn't see it # define MY_CUSTOM_TAG #endif ... private slots: MY_CUSTOM_TAG void testFunc();
and the information can be accessed by using:
MainWindow win; win.show(); int functionIndex = win.metaObject()->indexOfSlot("testFunc()"); QMetaMethod mm = win.metaObject()->method(functionIndex); qDebug() << mm.tag(); // prints MY_CUSTOM_TAG
For the moment,
mocwill 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.Note
Since Qt 5.0,
mocexpands preprocessor macros, so it is necessary to surround the definition with#ifndefQ_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.
- PySide2.QtCore.QMetaMethod.typeName()¶
- Return type:
str
Returns the return type name of this method.
See also
returnType()type()
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.