QMetaObject Struct
The QMetaObject class contains meta-information about Nt objects. More…
| Header | #include <QMetaObject> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | Call |
| typedef | StaticMetacallFunction |
Public Functions
Static Public Members
| bool | checkConnectArgs(const char *signal, const char *method) |
| bool | checkConnectArgs(const QMetaMethod &signal, const QMetaMethod &method) |
| QByteArray | normalizedSignature(const char *method) |
| QByteArray | normalizedType(const char *type) |
| bool | connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type = 0, int *types = nullptr) |
| bool | disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index) |
| void | connectSlotsByName(QObject *o) |
| void | activate(QObject *sender, int signal_index, void **argv) |
| void | activate(QObject *sender, const QMetaObject *mo, int local_signal_index, void **argv) |
| bool | 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()) |
| bool | invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, 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()) |
| bool | invokeMethod(QObject *obj, const char *member, 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()) |
| bool | invokeMethod(QObject *obj, const char *member, 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()) |
| bool | invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<Functor>>> *ret = nullptr) |
| bool | invokeMethod(QObject *context, Functor &&function, std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<Functor>>> *ret) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, Args &&...args) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Args &&...args) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument<Ret> ret, Args &&...args) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, QTemplatedMetaMethodReturnArgument<Ret> ret, Args &&...args) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, Ret *ret) |
| bool | invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Ret *ret) |
Detailed Description
Every class that declares Q_OBJECT or Q_GADGET and goes through ntmoc has a static QMetaObject, staticMetaObject, that describes its class name, base class, signals, slots, invokable methods, properties, enumerators and class information. For a QObject, metaObject() returns the meta-object of its dynamic type.
const QMetaObject *mo = obj->metaObject();
for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i)
qDebug() << mo->property(i).name();
Methods and properties are numbered across the inheritance chain: the base class has the lowest indexes, and methodOffset() and propertyOffset() give the first index of this class. Signals come first in a class, then slots, then Q_INVOKABLE methods, each in declaration order. A method with default arguments gets one extra entry for each shorter call.
See also QMetaMethod, QMetaProperty, QMetaEnum, QMetaClassInfo, QObject and Meta-Object System.
Differences from Qt
The layout of the public d data member is Nt's own and is not binary-compatible with Qt, and the code that ntmoc generates differs from that of Qt's moc. There are no qt_metacast() and qt_metacall() functions, no QMetaObject::tr() or changeGuard(), and qobject_cast() stays a wrapper around dynamic_cast. The invokeMethod() overloads that take the name of a method need Q_ARG() and Q_RETURN_ARG(); plain arguments and qReturnArg() are for the overloads that take a function. A class that ntmoc did not process has no meta-object of its own: QObject::metaObject() returns that of its nearest base class that has one.
Member Type Documentation
enum QMetaObject::Call
This enum describes the calls that a meta-object's static_metacall() function handles.
| Constant | Description |
|---|---|
QMetaObject::InvokeMetaMethod | Invoke a method. |
QMetaObject::ReadProperty | Read a property. |
QMetaObject::WriteProperty | Write a property. |
QMetaObject::ResetProperty | Reset a property. |
QMetaObject::CreateInstance | Create an instance with a constructor. |
QMetaObject::IndexOfMethod | Find the index of a method; unused by Nt. |
QMetaObject::RegisterPropertyMetaType | Get the QMetaType of a property. |
QMetaObject::RegisterMethodArgumentMetaType | Get the QMetaType of a method argument. |
QMetaObject::BindableProperty | Get the bindable of a property; unused by Nt. |
QMetaObject::CustomCall | A call that a class defines itself. |
QMetaObject::QueryPropertyDesignable | Ask whether a property is designable. |
QMetaObject::QueryPropertyScriptable | Ask whether a property is scriptable. |
QMetaObject::QueryPropertyStored | Ask whether a property is stored. |
QMetaObject::QueryPropertyUser | Ask whether a property is the user property. |
typedef QMetaObject::StaticMetacallFunction
The type of the function that ntmoc generates in each class to invoke methods and read and write properties; see QMetaObject::d.
Member Function Documentation
void QMetaObject::activate(QObject *sender, int signal_index, void **argv)
Emits the signal with the index signal_index of sender, with the arguments at argv, where argv[1] is the first one. argv[0] is reserved for a return value and is unused for signals. This is the call that a signal's generated body makes in Qt; Nt's ntmoc output does not use it, but code that does works.
See also QObject::connect().
void QMetaObject::activate(QObject *sender, const QMetaObject *mo, int local_signal_index, void **argv)
This is an overloaded function.
Emits the signal with the index local_signal_index in mo, a meta-object in the chain of the meta-objects of sender, with the arguments argv.
QObject * QMetaObject::cast(QObject *obj) const
Returns obj if it is an instance of the class this meta-object describes or of a class derived from it; otherwise returns nullptr.
See also inherits().
const QObject * QMetaObject::cast(const QObject *obj) const
This is an overloaded function.
Returns obj if it is an instance of this class or of a class derived from it; otherwise returns nullptr.
bool QMetaObject::checkConnectArgs(const char *signal, const char *method)
Returns true if the arguments of the slot or signal method are compatible with those of signal: method may have fewer arguments, and each of its types must equal the type of the signal argument in the same position. Both are given as signatures without the SIGNAL() or SLOT() prefix.
See also normalizedSignature().
bool QMetaObject::checkConnectArgs(const QMetaMethod &signal, const QMetaMethod &method)
This is an overloaded function.
Returns true if the arguments of method are compatible with those of signal.
QMetaClassInfo QMetaObject::classInfo(int index) const
Returns the class information entry at index, counting those of the base classes first, or an invalid QMetaClassInfo if index is out of range.
See also classInfoCount() and indexOfClassInfo().
int QMetaObject::classInfoCount() const
Returns the number of class information entries of this class, including those of its base classes.
See also classInfoOffset() and classInfo().
int QMetaObject::classInfoOffset() const
Returns the index of the first class information entry of this class.
See also classInfoCount() and classInfo().
const char * QMetaObject::className() const
Returns the name of the class this meta-object describes, including the names of the namespaces and classes that enclose it, such as "outer::Inner".
See also superClass().
bool QMetaObject::connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type = 0, int *types = nullptr)
Connects the signal with the index signal_index of sender to the method with the index method_index of receiver, and returns true on success. type is a Qt::ConnectionType and types is ignored.
See also QObject::connect() and disconnect().
void QMetaObject::connectSlotsByName(QObject *o)
Connects signals to slots by name, for each slot of o that is named on_<object name>_<signal name>(...). The object name is that of o or of one of its descendants, and the signal is a signal of that object whose arguments are compatible with the slot. A slot that finds no signal prints a warning.
See also QObject::setObjectName().
QMetaMethod QMetaObject::constructor(int index) const
Returns the meta-data of the constructor at index, or an invalid QMetaMethod if index is out of range.
See also constructorCount() and indexOfConstructor().
int QMetaObject::constructorCount() const
Returns the number of invokable constructors of this class. Constructors are not inherited.
See also constructor() and newInstance().
bool QMetaObject::disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Removes the connections from the signal with the index signal_index of sender to the method with the index method_index of receiver. A negative signal_index or method_index matches any signal or any method. Returns true if a connection was removed.
See also connect().
QMetaEnum QMetaObject::enumerator(int index) const
Returns the meta-data of the enumerator at index, counting the enumerators of the base classes first, or an invalid QMetaEnum if index is out of range.
See also enumeratorCount() and indexOfEnumerator().
int QMetaObject::enumeratorCount() const
Returns the number of enumerators of this class, including those of its base classes.
See also enumeratorOffset() and enumerator().
int QMetaObject::enumeratorOffset() const
Returns the index of the first enumerator of this class.
See also enumeratorCount() and enumerator().
int QMetaObject::indexOfClassInfo(const char *name) const
Returns the index of the class information entry called name, or -1 if there is none.
See also classInfo().
int QMetaObject::indexOfConstructor(const char *constructor) const
Returns the index of the constructor with the signature constructor, such as "Counter(QObject*)", or -1 if there is none.
See also constructor() and newInstance().
int QMetaObject::indexOfEnumerator(const char *name) const
Returns the index of the enumerator called name, or -1 if there is none. The name is that of the enumeration, without its scope.
See also enumerator().
int QMetaObject::indexOfMethod(const char *method) const
Returns the index of the signal, slot or invokable method with the signature method, such as "setValue(int)", or -1 if there is none. Base classes are searched too.
See also indexOfSignal(), indexOfSlot() and method().
int QMetaObject::indexOfProperty(const char *name) const
Returns the index of the property called name, or -1 if there is none.
See also property().
int QMetaObject::indexOfSignal(const char *signal) const
Returns the index of the signal with the signature signal, such as "valueChanged(int)", or -1 if there is none.
See also indexOfMethod() and indexOfSlot().
int QMetaObject::indexOfSlot(const char *slot) const
Returns the index of the slot with the signature slot, such as "setValue(int)", or -1 if there is none.
See also indexOfMethod() and indexOfSignal().
bool QMetaObject::inherits(const QMetaObject *metaObject) const
Returns true if the class described by this meta-object is metaObject or inherits from it; otherwise returns false.
See also cast() and superClass().
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 signal, slot or invokable method member of obj and returns true if it could be invoked. member is the name of the method without its parameters. The arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, made with Q_ARG(), select the overload by their types, and ret, made with Q_RETURN_ARG(), receives the return value.
type is how the call is made: with Qt::DirectConnection the method runs before the function returns, and with Qt::QueuedConnection it runs from the event loop of the thread of obj, with copies of the arguments. Qt::AutoConnection calls directly when obj lives in the calling thread and queues otherwise. Qt::BlockingQueuedConnection queues the call to another thread and waits for it, so it can return a value. A queued call cannot return a value, and its argument types must be registered with QMetaType.
QString result;
QMetaObject::invokeMethod(obj, "describe", Qt::DirectConnection,
Q_RETURN_ARG(QString, result), Q_ARG(int, 3));
The function prints a warning and returns false if obj has no such method or the argument types do not match.
See also QMetaMethod::invoke().
bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, 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())
This is an overloaded function.
Invokes member on obj with the connection type type, passing the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, and storing no return value.
bool QMetaObject::invokeMethod(QObject *obj, const char *member, 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())
This is an overloaded function.
Invokes member on obj with Qt::AutoConnection, storing the result in ret and passing the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9.
bool QMetaObject::invokeMethod(QObject *obj, const char *member, 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())
This is an overloaded function.
Invokes member on obj with Qt::AutoConnection, passing the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, and storing no return value.
template <typename Functor, typename = std::enable_if_t<std::is_invocable_v<Functor>>> bool QMetaObject::invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<Functor>>> *ret = nullptr)
This is an overloaded function.
Calls function in the context of context. With Qt::DirectConnection or Qt::AutoConnection it runs at once; with Qt::QueuedConnection it runs from the event loop, and ret must then be nullptr. If ret is not nullptr, the result is stored there. Returns false if context is nullptr.
template <typename Functor, typename = std::enable_if_t<std::is_invocable_v<Functor>>> bool QMetaObject::invokeMethod(QObject *context, Functor &&function, std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<Functor>>> *ret)
This is an overloaded function.
Calls function in the context of context with Qt::AutoConnection and stores the result in ret.
template <typename Functor, typename... Args, std::enable_if_t<QtPrivate::InvokesWithArguments<Functor, Args...>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, Args &&...args)
This is an overloaded function.
Calls function with the arguments args in the context of context, using the connection type type, and returns true if the call was made or queued. function is a pointer to a member function of the class of context, which is called on context, or a functor that takes args:
QMetaObject::invokeMethod(&label, &Label::setText, Qt::QueuedConnection, QString("Done"));
QMetaObject::invokeMethod(&label, [](int code) { report(code); }, Qt::QueuedConnection, 3);
A queued call copies function and args, and runs when control returns to the event loop of the thread of context; nothing runs if context is destroyed first. The arguments are checked when the call is compiled, so their types need not be registered with QMetaType. Returns false if context is nullptr.
This function was introduced in 6.7.
template <typename Functor, typename... Args, std::enable_if_t<QtPrivate::InvokesWithArguments<Functor, Args...>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Args &&...args)
This is an overloaded function.
Calls function with the arguments args in the context of context with Qt::AutoConnection: at once if context lives in the calling thread, and from the event loop of its thread otherwise.
This function was introduced in 6.7.
template <typename Functor, typename Ret, typename... Args, std::enable_if_t<QtPrivate::CanInvoke<Functor, Args...>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument<Ret> ret, Args &&...args)
This is an overloaded function.
Calls function with the arguments args in the context of context, using the connection type type, and stores the result in the variable that ret refers to; create ret with qReturnArg(). A queued call cannot return a value, so the function returns false if the call would be queued.
This function was introduced in 6.7.
template <typename Functor, typename Ret, typename... Args, std::enable_if_t<QtPrivate::CanInvoke<Functor, Args...>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, QTemplatedMetaMethodReturnArgument<Ret> ret, Args &&...args)
This is an overloaded function.
Calls function with the arguments args in the context of context with Qt::AutoConnection and stores the result in the variable that ret refers to.
This function was introduced in 6.7.
template <typename Functor, typename Ret, std::enable_if_t< std::is_member_function_pointer_v<std::decay_t<Functor>> && QtPrivate::CanInvoke<Functor>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Qt::ConnectionType type, Ret *ret)
This is an overloaded function.
Calls function, a pointer to a member function without parameters, on context using the connection type type, and stores the result in ret.
This function was introduced in 5.10.
template <typename Functor, typename Ret, std::enable_if_t< std::is_member_function_pointer_v<std::decay_t<Functor>> && QtPrivate::CanInvoke<Functor>, int> = 0> bool QMetaObject::invokeMethod(typename QtPrivate::InvokeContext<std::decay_t<Functor>>::type *context, Functor &&function, Ret *ret)
This is an overloaded function.
Calls function, a pointer to a member function without parameters, on context with Qt::AutoConnection and stores the result in ret.
This function was introduced in 5.10.
QMetaMethod QMetaObject::method(int index) const
Returns the meta-data of the method at index, counting the methods of the base classes first, or an invalid QMetaMethod if index is out of range.
See also methodCount() and indexOfMethod().
int QMetaObject::methodCount() const
Returns the number of methods of this class, including those of its base classes.
See also methodOffset() and method().
int QMetaObject::methodOffset() const
Returns the index of the first method of this class: the number of methods of its base classes.
See also methodCount() and method().
QObject * QMetaObject::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 of the class with a constructor that takes the arguments val0, val1, val2, val3, val4, val5, val6, val7, val8 and val9, and returns it, or nullptr if there is no such constructor. Only constructors declared with Q_INVOKABLE are known.
See also QMetaMethod::newInstance() and constructor().
QByteArray QMetaObject::normalizedSignature(const char *method)
Returns method as a normalized signature: no whitespace except in type names that need it, const and & removed from by-value and const-reference parameters, and the spelled-out names of fundamental types abbreviated. For example, "setValue( const QString & , unsigned int )" becomes "setValue(QString,uint)".
See also normalizedType().
QByteArray QMetaObject::normalizedType(const char *type)
Returns type as a normalized type name; see normalizedSignature().
QMetaProperty QMetaObject::property(int index) const
Returns the meta-data of the property at index, counting the properties of the base classes first, or an invalid QMetaProperty if index is out of range.
See also propertyCount() and indexOfProperty().
int QMetaObject::propertyCount() const
Returns the number of properties of this class, including those of its base classes.
See also propertyOffset() and property().
int QMetaObject::propertyOffset() const
Returns the index of the first property of this class.
See also propertyCount() and property().
const QMetaObject * QMetaObject::superClass() const
Returns the meta-object of the base class, or nullptr if there is none.
See also inherits().
QMetaProperty QMetaObject::userProperty() const
Returns the property that has the USER attribute set, or an invalid QMetaProperty if there is none.
See also QMetaProperty::isUser().