PySide6.QtCore.QMetaObject¶
- class QMetaObject¶
The
QMetaObjectclass contains meta-information about Qt objects.Details
The Qt Meta-Object System in Qt is responsible for the signals and slots inter-object communication mechanism, runtime type information, and the Qt property system. A single
QMetaObjectinstance is created for eachQObjectsubclass that is used in an application, and this instance stores all the meta-information for theQObjectsubclass. This object is available asmetaObject().This class is not normally required for application programming, but it is useful if you write meta-applications, such as scripting engines or GUI builders.
The functions you are most likely to find useful are these:
className()returns the name of a class.superClass()returns the superclass’s meta-object.method()andmethodCount()provide information about a class’s meta-methods (signals, slots and otherinvokablemember functions).enumerator()andenumeratorCount()and provide information about a class’s enumerators.propertyCount()andproperty()provide information about a class’s properties.constructor()andconstructorCount()provide information about a class’s meta-constructors.
The index functions
indexOfConstructor(),indexOfMethod(),indexOfEnumerator(), andindexOfProperty()map names of constructors, member functions, enumerators, or properties to indexes in the meta-object. For example, Qt usesindexOfMethod()internally when you connect a signal to a slot.Classes can also have a list of name–value pairs of additional class information, stored in
QMetaClassInfoobjects. The number of pairs is returned byclassInfoCount(), single pairs are returned byclassInfo(), and you can search for pairs withindexOfClassInfo().Note
Operations that use the meta object system are generally thread- safe, as QMetaObjects are typically static read-only instances generated at compile time. However, if meta objects are dynamically modified by the application (for instance, when using QQmlPropertyMap), then the application has to explicitly synchronize access to the respective meta object.
Synopsis¶
Methods¶
def
__repr__()def
cast()def
classInfo()def
classInfoCount()def
className()def
constructor()def
enumerator()def
indexOfMethod()def
indexOfSignal()def
indexOfSlot()def
inherits()def
metaType()def
method()def
methodCount()def
methodOffset()def
newInstance()def
property()def
propertyCount()def
propertyOffset()def
superClass()def
userProperty()
Static functions¶
def
disconnect()def
disconnectOne()def
invokeMethod()def
normalizedType()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- class Call¶
- __repr__()¶
- Return type:
str
- static checkConnectArgs(signal, method)¶
- Parameters:
signal –
QMetaMethodmethod –
QMetaMethod
- Return type:
bool
Returns
trueif thesignalandmethodarguments are compatible; otherwise returnsfalse.- static checkConnectArgs(signal, method)
- Parameters:
signal – str
method – str
- Return type:
bool
Returns
trueif thesignalandmethodarguments are compatible; otherwise returnsfalse.Both
signalandmethodare expected to be normalized.See also
- classInfo(index)¶
- Parameters:
index – int
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns the meta-data for the item of class information with the given
index.Example:
class MyClass(QObject): Q_OBJECT Q_CLASSINFO("author", "Sabrina Schweinsteiger") Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") # public ...
- classInfoCount()¶
- Return type:
int
Returns the number of items of class information in this class.
- classInfoOffset()¶
- Return type:
int
Returns the class information offset for this class; i.e. the index position of this class’s first class information item.
If the class has no superclasses with class information, the offset is 0; otherwise the offset is the sum of all the class information items in the class’s superclasses.
- className()¶
- Return type:
str
Returns the class name.
See also
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Searches recursively for all child objects of the given
object, and connects matching signals from them to slots ofobjectthat follow the following form:on_<object = void(<signal parameters>)
Let’s assume our object has a child object of type
QPushButtonwith theobject namebutton1. The slot to catch the button’sclicked()signal would be:def on_button1_clicked():
If
objectitself has a properly set object name, its own signals are also connected to its respective slots.See also
- constructor(index)¶
- Parameters:
index – int
- Return type:
Returns the meta-data for the constructor with the given
index.See also
- constructorCount()¶
- Return type:
int
Returns the number of constructors in this class.
See also
- static disconnect(sender, signal_index, receiver, method_index)¶
- static disconnectOne(sender, signal_index, receiver, method_index)¶
Returns the meta-data for the enumerator with the given
index.- enumeratorCount()¶
- Return type:
int
Returns the number of enumerators in this class.
- enumeratorOffset()¶
- Return type:
int
Returns the enumerator offset for this class; i.e. the index position of this class’s first enumerator.
If the class has no superclasses with enumerators, the offset is 0; otherwise the offset is the sum of all the enumerators in the class’s superclasses.
- indexOfClassInfo(name)¶
- Parameters:
name – str
- Return type:
int
Finds class information item
nameand returns its index; otherwise returns -1.See also
- indexOfConstructor(constructor)¶
- Parameters:
constructor – str
- Return type:
int
Finds
constructorand returns its index; otherwise returns -1.Note that the
constructorhas to be in normalized form, as returned bynormalizedSignature().- indexOfEnumerator(name)¶
- Parameters:
name – str
- Return type:
int
Finds enumerator
nameand returns its index; otherwise returns -1.- indexOfMethod(method)¶
- Parameters:
method – str
- Return type:
int
Finds
methodand returns its index; otherwise returns -1.Note that the
methodhas to be in normalized form, as returned bynormalizedSignature().- indexOfProperty(name)¶
- Parameters:
name – str
- Return type:
int
Finds property
nameand returns its index; otherwise returns -1.See also
- indexOfSignal(signal)¶
- Parameters:
signal – str
- Return type:
int
Finds
signaland returns its index; otherwise returns -1.This is the same as
indexOfMethod(), except that it will return -1 if the method exists but isn’t a signal.Note that the
signalhas to be in normalized form, as returned bynormalizedSignature().- indexOfSlot(slot)¶
- Parameters:
slot – str
- Return type:
int
Finds
slotand returns its index; otherwise returns -1.This is the same as
indexOfMethod(), except that it will return -1 if the method exists but isn’t a slot.- inherits(metaObject)¶
- Parameters:
metaObject –
QMetaObject- Return type:
bool
Returns
trueif the class described by thisQMetaObjectinherits the type described bymetaObject; otherwise returns false.A type is considered to inherit itself.
- static invokeMethod(obj, member, val0[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]])¶
- Parameters:
obj –
QObjectmember – str
val0 –
QGenericArgumentval1 –
QGenericArgumentval2 –
QGenericArgumentval3 –
QGenericArgumentval4 –
QGenericArgumentval5 –
QGenericArgumentval6 –
QGenericArgumentval7 –
QGenericArgumentval8 –
QGenericArgumentval9 –
QGenericArgument
- Return type:
bool
Please use the variadic overload of this function.
This overload invokes the member using the connection type
AutoConnectionand ignores return values.- static invokeMethod(object, member[, val0={}[, val1={}[, val2={}[, val3={}[, val4={}[, val5={}[, val6={}[, val7={}[, val8={}[, val9={}]]]]]]]]]])
- Parameters:
object –
QObjectmember – str
val0 –
QGenericArgumentHolderval1 –
QGenericArgumentHolderval2 –
QGenericArgumentHolderval3 –
QGenericArgumentHolderval4 –
QGenericArgumentHolderval5 –
QGenericArgumentHolderval6 –
QGenericArgumentHolderval7 –
QGenericArgumentHolderval8 –
QGenericArgumentHolderval9 –
QGenericArgumentHolder
- Return type:
bool
- static invokeMethod(obj, member, ret[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
obj –
QObjectmember – str
ret –
QGenericReturnArgumentval0 –
QGenericArgumentval1 –
QGenericArgumentval2 –
QGenericArgumentval3 –
QGenericArgumentval4 –
QGenericArgumentval5 –
QGenericArgumentval6 –
QGenericArgumentval7 –
QGenericArgumentval8 –
QGenericArgumentval9 –
QGenericArgument
- Return type:
bool
Please use the variadic overload of this function.
This overload always invokes the member using the connection type
AutoConnection.- static invokeMethod(obj, member, type, val0[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]])
- Parameters:
obj –
QObjectmember – str
type –
ConnectionTypeval0 –
QGenericArgumentval1 –
QGenericArgumentval2 –
QGenericArgumentval3 –
QGenericArgumentval4 –
QGenericArgumentval5 –
QGenericArgumentval6 –
QGenericArgumentval7 –
QGenericArgumentval8 –
QGenericArgumentval9 –
QGenericArgument
- Return type:
bool
Please use the variadic overload of this function.
This overload can be used if the return value of the member is of no interest.
- static invokeMethod(object, member, type[, val0={}[, val1={}[, val2={}[, val3={}[, val4={}[, val5={}[, val6={}[, val7={}[, val8={}[, val9={}]]]]]]]]]])
- Parameters:
object –
QObjectmember – str
type –
ConnectionTypeval0 –
QGenericArgumentHolderval1 –
QGenericArgumentHolderval2 –
QGenericArgumentHolderval3 –
QGenericArgumentHolderval4 –
QGenericArgumentHolderval5 –
QGenericArgumentHolderval6 –
QGenericArgumentHolderval7 –
QGenericArgumentHolderval8 –
QGenericArgumentHolderval9 –
QGenericArgumentHolder
- Return type:
bool
- static invokeMethod(object, member, ret[, val0={}[, val1={}[, val2={}[, val3={}[, val4={}[, val5={}[, val6={}[, val7={}[, val8={}[, val9={}]]]]]]]]]])
- Parameters:
object –
QObjectmember – str
ret –
QGenericReturnArgumentHolderval0 –
QGenericArgumentHolderval1 –
QGenericArgumentHolderval2 –
QGenericArgumentHolderval3 –
QGenericArgumentHolderval4 –
QGenericArgumentHolderval5 –
QGenericArgumentHolderval6 –
QGenericArgumentHolderval7 –
QGenericArgumentHolderval8 –
QGenericArgumentHolderval9 –
QGenericArgumentHolder
- Return type:
object
- static invokeMethod(obj, member, type, ret[, val0=QGenericArgument(nullptr)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
- Parameters:
obj –
QObjectmember – str
type –
ConnectionTyperet –
QGenericReturnArgumentval0 –
QGenericArgumentval1 –
QGenericArgumentval2 –
QGenericArgumentval3 –
QGenericArgumentval4 –
QGenericArgumentval5 –
QGenericArgumentval6 –
QGenericArgumentval7 –
QGenericArgumentval8 –
QGenericArgumentval9 –
QGenericArgument
- Return type:
bool
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Please use the variadic overload of this function
Invokes the
member(a signal or a slot name) on the objectobj. Returnstrueif the member could be invoked. Returnsfalseif 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:The number of parameters is limited to 10.
Parameter names may need to be an exact string match.
Meta types are not automatically registered.
With asynchronous method invocations, the parameters must be of types that are already 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
QMetaObject.invokeMethod: Unable to handle unregistered datatype 'MyType'
call
qRegisterMetaType()to register the data type before you callinvokeMethod().See also
Q_ARG()Q_RETURN_ARG()qRegisterMetaType()invoke()- static invokeMethod(object, member, type, ret[, val0={}[, val1={}[, val2={}[, val3={}[, val4={}[, val5={}[, val6={}[, val7={}[, val8={}[, val9={}]]]]]]]]]])
- Parameters:
object –
QObjectmember – str
type –
ConnectionTyperet –
QGenericReturnArgumentHolderval0 –
QGenericArgumentHolderval1 –
QGenericArgumentHolderval2 –
QGenericArgumentHolderval3 –
QGenericArgumentHolderval4 –
QGenericArgumentHolderval5 –
QGenericArgumentHolderval6 –
QGenericArgumentHolderval7 –
QGenericArgumentHolderval8 –
QGenericArgumentHolderval9 –
QGenericArgumentHolder
- Return type:
object
Returns the metatype corresponding to this metaobject. If the metaobject originates from a namespace, an invalid metatype is returned.
- method(index)¶
- Parameters:
index – int
- Return type:
Returns the meta-data for the method with the given
index.See also
- methodCount()¶
- Return type:
int
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns the number of methods in this class, including the number of methods provided by each base class. These include signals and slots as well as normal member functions.
Use code like the following to obtain a
QStringListcontaining the methods specific to a given class:QMetaObject* metaObject = obj.metaObject() methods = QStringList() for i in range(metaObject.methodOffset(), metaObject.methodCount()): methods << QString.fromLatin1(metaObject.method(i).methodSignature())
See also
- methodOffset()¶
- Return type:
int
Returns the method offset for this class; i.e. the index position of this class’s first member function.
The offset is the sum of all the methods in the class’s superclasses (which is always positive since
QObjecthas thedeleteLater()slot and adestroyed()signal).See also
- newInstance(val0[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]])¶
- Parameters:
val0 –
QGenericArgumentval1 –
QGenericArgumentval2 –
QGenericArgumentval3 –
QGenericArgumentval4 –
QGenericArgumentval5 –
QGenericArgumentval6 –
QGenericArgumentval7 –
QGenericArgumentval8 –
QGenericArgumentval9 –
QGenericArgument
- Return type:
Please use the variadic overload of this function
Constructs a new instance of this class. You can pass up to ten arguments (
val0,val1,val2,val3,val4,val5,val6,val7,val8, andval9) to the constructor. Returns the new object, orNoneif no suitable constructor is available.Note that only constructors that are declared with the
Q_INVOKABLEmodifier are made available through the meta-object system.See also
Q_ARG()constructor()- static normalizedSignature(method)¶
- Parameters:
method – str
- Return type:
Normalizes the signature of the given
method.Qt uses normalized signatures to decide whether two given signals and slots are compatible. Normalization reduces whitespace to a minimum, moves ‘const’ to the front where appropriate, removes ‘const’ from value types and replaces const references with values.
See also
- static normalizedType(type)¶
- Parameters:
type – str
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Normalizes a
type.See
normalizedSignature()for a description on how Qt normalizes.Example:
normType = QMetaObject.normalizedType(" int *") # normType is now "const int*"
See also
- property(index)¶
- Parameters:
index – int
- Return type:
Returns the meta-data for the property with the given
index. If no such property exists, a nullQMetaPropertyis returned.- propertyCount()¶
- Return type:
int
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns the number of properties in this class, including the number of properties provided by each base class.
Use code like the following to obtain a
QStringListcontaining the properties specific to a given class:QMetaObject* metaObject = obj.metaObject() properties = QStringList() for i in range(metaObject.propertyOffset(), metaObject.propertyCount()): properties << QString.fromLatin1(metaObject.property(i).name())
See also
- propertyOffset()¶
- Return type:
int
Returns the property offset for this class; i.e. the index position of this class’s first property.
The offset is the sum of all the properties in the class’s superclasses (which is always positive since
QObjecthas theobjectNameproperty).See also
- superClass()¶
- Return type:
Returns the meta-object of the superclass, or
Noneif there is no such object.See also
- userProperty()¶
- Return type:
Returns the property that has the
USERflag set to true.See also
- class Connection¶
Synopsis¶
Methods¶
def
__init__()def
swap()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Represents a handle to a signal-slot (or signal-functor) connection.
It can be used to check if the connection is valid and to disconnect it using
disconnect(). For a signal-functor connection without a context object, it is the only way to selectively disconnect that connection.As Connection is just a handle, the underlying signal-slot connection is unaffected when Connection is destroyed or reassigned.
- __init__()¶
Creates a Connection instance.
- __init__(other)
- Parameters:
other –
Connection
Create a copy of the handle to the
otherconnection- swap(other)¶
- Parameters:
other –
Connection
Swaps this Connection instance with
other. This operation is very fast and never fails.