▲
-
Header: QMetaObject
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Group: QMetaObject is part of objectmodel
Detailed Description▲
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 QMetaObject instance is created for each QObject subclass that is used in an application, and this instance stores all the meta-information for the 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:
-
className() returns the name of a class.
-
superClass() returns the superclass's meta-object.
-
method() and methodCount() provide information about a class's meta-methods (signals, slots and other invokable member functions).
-
enumerator() and enumeratorCount() and provide information about a class's enumerators.
-
propertyCount() and property() provide information about a class's properties.
-
constructor() and constructorCount() provide information about a class's meta-constructors.
The index functions indexOfConstructor(), indexOfMethod(), indexOfEnumerator(), and indexOfProperty() map names of constructors, member functions, enumerators, or properties to indexes in the meta-object. For example, Qt uses indexOfMethod() 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 QMetaClassInfo objects. The number of pairs is returned by classInfoCount(), single pairs are returned by classInfo(), and you can search for pairs with indexOfClassInfo().
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.
See Also▲
See also QMetaClassInfo, QMetaEnum, QMetaMethod, QMetaProperty, QMetaType, Meta-Object System
Member Function Documentation▲
[static] bool QMetaObject::checkConnectArgs(const char *signal, const char *method)▲
Returns true if the signal and method arguments are compatible; otherwise returns false.
Both signal and method are expected to be normalized.
See Also▲
See also normalizedSignature()
[static, since 5.0] bool QMetaObject::checkConnectArgs(const QMetaMethod &signal, const QMetaMethod &method)▲
This is an overloaded function.
Returns true if the signal and method arguments are compatible; otherwise returns false.
This function was introduced in Qt 5.0.
QMetaClassInfo QMetaObject::classInfo(int index) const▲
Returns the meta-data for the item of class information with the given index.
Example:
class
MyClass : public
QObject
{
Q_OBJECT
Q_CLASSINFO("author"
, "Sabrina Schweinsteiger"
)
Q_CLASSINFO("url"
, "http://doc.moosesoft.co.uk/1.0/"
)
public
:
...
}
;
See Also▲
See also classInfoCount(), classInfoOffset(), indexOfClassInfo()
int QMetaObject::classInfoCount() const▲
Returns the number of items of class information in this class.
See Also▲
See also classInfo(), classInfoOffset(), indexOfClassInfo()
int QMetaObject::classInfoOffset() const▲
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.
See Also▲
See also classInfo(), classInfoCount(), indexOfClassInfo()
const char *QMetaObject::className() const▲
[static] void QMetaObject::connectSlotsByName(QObject *object)▲
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:
void
on_&
lt;object name&
gt;_&
lt;signal name&
gt;(&
lt;signal parameters&
gt;);
Let's assume our object has a child object of type QPushButton with the object name button1. The slot to catch the button's clicked() signal would be:
void
on_button1_clicked();
If object itself has a properly set object name, its own signals are also connected to its respective slots.
See Also▲
See also QObject::setObjectName()
QMetaMethod QMetaObject::constructor(int index) const▲
Returns the meta-data for the constructor with the given index.
See Also▲
See also constructorCount(), newInstance()
int QMetaObject::constructorCount() const▲
Returns the number of constructors in this class.
See Also▲
See also constructor(), indexOfConstructor()
QMetaEnum QMetaObject::enumerator(int index) const▲
Returns the meta-data for the enumerator with the given index.
See Also▲
See also enumeratorCount(), enumeratorOffset(), indexOfEnumerator()
int QMetaObject::enumeratorCount() const▲
Returns the number of enumerators in this class.
See Also▲
See also enumerator(), enumeratorOffset(), indexOfEnumerator()
int QMetaObject::enumeratorOffset() const▲
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.
See Also▲
See also enumerator(), enumeratorCount(), indexOfEnumerator()
int QMetaObject::indexOfClassInfo(const char *name) const▲
Finds class information item name and returns its index; otherwise returns -1.
See Also▲
See also classInfo(), classInfoCount(), classInfoOffset()
int QMetaObject::indexOfConstructor(const char *constructor) const▲
Finds constructor and returns its index; otherwise returns -1.
Note that the constructor has to be in normalized form, as returned by normalizedSignature().
See Also▲
See also constructor(), constructorCount(), normalizedSignature()
int QMetaObject::indexOfEnumerator(const char *name) const▲
Finds enumerator name and returns its index; otherwise returns -1.
See Also▲
See also enumerator(), enumeratorCount(), enumeratorOffset()
int QMetaObject::indexOfMethod(const char *method) const▲
Finds method and returns its index; otherwise returns -1.
Note that the method has to be in normalized form, as returned by normalizedSignature().
See Also▲
See also method(), methodCount(), methodOffset(), normalizedSignature()
int QMetaObject::indexOfProperty(const char *name) const▲
Finds property name and returns its index; otherwise returns -1.
See Also▲
See also property(), propertyCount(), propertyOffset()
int QMetaObject::indexOfSignal(const char *signal) const▲
Finds signal and 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 signal has to be in normalized form, as returned by normalizedSignature().
See Also▲
See also indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset()
int QMetaObject::indexOfSlot(const char *slot) const▲
Finds slot and 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.
See Also▲
See also indexOfMethod(), method(), methodCount(), methodOffset()
[since 5.7] bool QMetaObject::inherits(const QMetaObject *metaObject) const▲
Returns true if the class described by this QMetaObject inherits the type described by metaObject; otherwise returns false.
A type is considered to inherit itself.
This function was introduced in Qt 5.7.
[static] bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, 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())▲
Invokes the member (a signal or a slot name) on the object obj. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.
The invocation can be either synchronous or asynchronous, depending on type:
-
If type is Qt::DirectConnection, the member will be invoked immediately.
-
If type is Qt::QueuedConnection, a QEvent will be sent and the member is invoked as soon as the application enters the main event loop.
-
If type is Qt::BlockingQueuedConnection, the method will be invoked in the same way as for Qt::QueuedConnection, except that the current thread will block until the event is delivered. Using this connection type to communicate between objects in the same thread will lead to deadlocks.
-
If type is Qt::AutoConnection, the member is invoked synchronously if obj lives in the same thread as the caller; otherwise it will invoke the member asynchronously.
The return value of the member function call is placed in