QMetaObject

Synopsis

Functions

Static functions

  • def checkConnectArgs (signal, method)
  • def connectSlotsByName (o)
  • def disconnect (sender, signal_index, receiver, method_index)
  • def invokeMethod (obj, member, arg__3, ret[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
  • def invokeMethod (obj, member, ret[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
  • def invokeMethod (obj, member, type[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
  • def invokeMethod (obj, member[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
  • def normalizedSignature (method)
  • def normalizedType (type)

Detailed Description

The PySide.QtCore.QMetaObject class contains meta-information about Qt objects.

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 PySide.QtCore.QMetaObject instance is created for each PySide.QtCore.QObject subclass that is used in an application, and this instance stores all the meta-information for the PySide.QtCore.QObject subclass. This object is available as QObject.metaObject() .

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:

The index functions PySide.QtCore.QMetaObject.indexOfConstructor() , PySide.QtCore.QMetaObject.indexOfMethod() , PySide.QtCore.QMetaObject.indexOfEnumerator() , and PySide.QtCore.QMetaObject.indexOfProperty() map names of constructors, member functions, enumerators, or properties to indexes in the meta-object. For example, Qt uses PySide.QtCore.QMetaObject.indexOfMethod() internally when you connect a signal to a slot.

Classes can also have a list of namevalue pairs of additional class information, stored in PySide.QtCore.QMetaClassInfo objects. The number of pairs is returned by PySide.QtCore.QMetaObject.classInfoCount() , single pairs are returned by PySide.QtCore.QMetaObject.classInfo() , and you can search for pairs with PySide.QtCore.QMetaObject.indexOfClassInfo() .

class PySide.QtCore.QMetaObject
PySide.QtCore.QMetaObject.Call
Constant Description
QMetaObject.InvokeSlot  
QMetaObject.EmitSignal  
QMetaObject.ReadProperty  
QMetaObject.WriteProperty  
QMetaObject.ResetProperty  
QMetaObject.QueryPropertyDesignable  
QMetaObject.QueryPropertyScriptable  
QMetaObject.QueryPropertyStored  
QMetaObject.QueryPropertyEditable  
QMetaObject.QueryPropertyUser  
QMetaObject.CreateInstance  
PySide.QtCore.QMetaObject.cast(obj)
Parameters:objPySide.QtCore.QObject
Return type:PySide.QtCore.QObject

Returns obj if object obj inherits from this meta-object; otherwise returns 0.

static PySide.QtCore.QMetaObject.checkConnectArgs(signal, method)
Parameters:
  • signal – str
  • method – str
Return type:

PySide.QtCore.bool

Returns true if the signal and method arguments are compatible; otherwise returns false.

Both signal and method are expected to be normalized.

PySide.QtCore.QMetaObject.classInfo(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QMetaClassInfo

Returns the meta-data for the item of class information with the given index .

Example:

class MyClass:

    Q_CLASSINFO("author", "Sabrina Schweinsteiger")
    Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/")

    ...
PySide.QtCore.QMetaObject.classInfoCount()
Return type:PySide.QtCore.int

Returns the number of items of class information in this class.

PySide.QtCore.QMetaObject.classInfoOffset()
Return type:PySide.QtCore.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.

PySide.QtCore.QMetaObject.className()
Return type:str

Returns the class name.

static PySide.QtCore.QMetaObject.connectSlotsByName(o)
Parameters:oPySide.QtCore.QObject

Searches recursively for all child objects of the given object , and connects matching signals from them to slots of object that follow the following form:

def on_<object name>_<signal name>(<signal parameters>)

Let’s assume our object has a child object of type PySide.QtGui.QPushButton with the object name button1 . The slot to catch the button’s clicked() signal would be:

def on_button1_clicked()
PySide.QtCore.QMetaObject.constructor(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QMetaMethod

Returns the meta-data for the constructor with the given index .

PySide.QtCore.QMetaObject.constructorCount()
Return type:PySide.QtCore.int

Returns the number of constructors in this class.

static PySide.QtCore.QMetaObject.disconnect(sender, signal_index, receiver, method_index)
Parameters:
Return type:

PySide.QtCore.bool

PySide.QtCore.QMetaObject.enumerator(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QMetaEnum

Returns the meta-data for the enumerator with the given index .

PySide.QtCore.QMetaObject.enumeratorCount()
Return type:PySide.QtCore.int

Returns the number of enumerators in this class.

PySide.QtCore.QMetaObject.enumeratorOffset()
Return type:PySide.QtCore.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.

PySide.QtCore.QMetaObject.indexOfClassInfo(name)
Parameters:name – str
Return type:PySide.QtCore.int

Finds class information item name and returns its index; otherwise returns -1.

PySide.QtCore.QMetaObject.indexOfConstructor(constructor)
Parameters:constructor – str
Return type:PySide.QtCore.int

Finds constructor and returns its index; otherwise returns -1.

Note that the constructor has to be in normalized form, as returned by PySide.QtCore.QMetaObject.normalizedSignature() .

PySide.QtCore.QMetaObject.indexOfEnumerator(name)
Parameters:name – str
Return type:PySide.QtCore.int

Finds enumerator name and returns its index; otherwise returns -1.

PySide.QtCore.QMetaObject.indexOfMethod(method)
Parameters:method – str
Return type:PySide.QtCore.int

Finds method and returns its index; otherwise returns -1.

Note that the method has to be in normalized form, as returned by PySide.QtCore.QMetaObject.normalizedSignature() .

PySide.QtCore.QMetaObject.indexOfProperty(name)
Parameters:name – str
Return type:PySide.QtCore.int

Finds property name and returns its index; otherwise returns -1.

PySide.QtCore.QMetaObject.indexOfSignal(signal)
Parameters:signal – str
Return type:PySide.QtCore.int

Finds signal and returns its index; otherwise returns -1.

This is the same as PySide.QtCore.QMetaObject.indexOfMethod() , except that it will return -1 if the method exists but isn’t a signal.

Note that the signal has to be in normalized form, as returned by PySide.QtCore.QMetaObject.normalizedSignature() .

PySide.QtCore.QMetaObject.indexOfSlot(slot)
Parameters:slot – str
Return type:PySide.QtCore.int

Finds slot and returns its index; otherwise returns -1.

This is the same as PySide.QtCore.QMetaObject.indexOfMethod() , except that it will return -1 if the method exists but isn’t a slot.

static PySide.QtCore.QMetaObject.invokeMethod(obj, member, type[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
Parameters:
Return type:

PySide.QtCore.bool

static PySide.QtCore.QMetaObject.invokeMethod(obj, member, arg__3, ret[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
Parameters:
Return type:

PySide.QtCore.bool

static PySide.QtCore.QMetaObject.invokeMethod(obj, member, ret[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
Parameters:
Return type:

PySide.QtCore.bool

This function overloads PySide.QtCore.QMetaObject.invokeMethod() .

This overload always invokes the member using the connection type Qt.AutoConnection .

static PySide.QtCore.QMetaObject.invokeMethod(obj, member[, val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
Parameters:
Return type:

PySide.QtCore.bool

This function overloads PySide.QtCore.QMetaObject.invokeMethod() .

This overload invokes the member using the connection type Qt.AutoConnection and ignores return values.

PySide.QtCore.QMetaObject.method(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QMetaMethod

Returns the meta-data for the method with the given index .

PySide.QtCore.QMetaObject.methodCount()
Return type:PySide.QtCore.int

Returns the number of methods known to the meta-object system in this class, including the number of properties provided by each base class. These include signals and slots as well as member functions declared with the Q_INVOKABLE() macro.

Use code like the following to obtain a PySide.QtCore.QStringList containing the methods specific to a given class:

metaObject = obj.metaObject()
methods = [metaObject.method(i).signature() for i in range(metaObject.methodOffset(), metaObject.methodCount())]
PySide.QtCore.QMetaObject.methodOffset()
Return type:PySide.QtCore.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 PySide.QtCore.QObject has the deleteLater() slot and a destroyed() signal).

PySide.QtCore.QMetaObject.newInstance([val0=QGenericArgument(0)[, val1=QGenericArgument()[, val2=QGenericArgument()[, val3=QGenericArgument()[, val4=QGenericArgument()[, val5=QGenericArgument()[, val6=QGenericArgument()[, val7=QGenericArgument()[, val8=QGenericArgument()[, val9=QGenericArgument()]]]]]]]]]])
Parameters:
Return type:

PySide.QtCore.QObject

Constructs a new instance of this class. You can pass up to ten arguments (val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , val8 , and val9 ) to the constructor. Returns the new object, or 0 if no suitable constructor is available.

Note that only constructors that are declared with the Q_INVOKABLE() modifier are made available through the meta-object system.

static PySide.QtCore.QMetaObject.normalizedSignature(method)
Parameters:method – str
Return type:PySide.QtCore.QByteArray

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.

static PySide.QtCore.QMetaObject.normalizedType(type)
Parameters:type – str
Return type:PySide.QtCore.QByteArray

Normalizes a type .

See QMetaObject.normalizedSignature() for a description on how Qt normalizes.

Example:

normType = QMetaObject.normalizedType(" int    const  *")
# normType is now "const int*"
PySide.QtCore.QMetaObject.property(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QMetaProperty

Returns the meta-data for the property with the given index . If no such property exists, a null PySide.QtCore.QMetaProperty is returned.

PySide.QtCore.QMetaObject.propertyCount()
Return type:PySide.QtCore.int

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 PySide.QtCore.QStringList containing the properties specific to a given class:

metaObject = obj.metaObject()
properties = [metaObject.property(i).name() for i in range(metaObject.propertyOffset(), metaObject.propertyCount())]
PySide.QtCore.QMetaObject.propertyOffset()
Return type:PySide.QtCore.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 PySide.QtCore.QObject has the name() property).

PySide.QtCore.QMetaObject.superClass()
Return type:PySide.QtCore.QMetaObject

Returns the meta-object of the superclass, or 0 if there is no such object.

PySide.QtCore.QMetaObject.userProperty()
Return type:PySide.QtCore.QMetaProperty

Returns the property that has the USER flag set to true.