QtBase
v6.3.1
|
The QMetaObject class contains meta-information about Qt objects. More...
#include <qobjectdefs.h>
Classes | |
struct | Data |
struct | SuperData |
Public Types | |
enum | Call { InvokeMetaMethod , ReadProperty , WriteProperty , ResetProperty , CreateInstance , IndexOfMethod , RegisterPropertyMetaType , RegisterMethodArgumentMetaType , BindableProperty } |
typedef void *Connection::* | RestrictedBool |
Public Attributes | |
struct QMetaObject::Data | d |
Friends | |
class | QTimer |
class | QObject |
class | QObjectPrivate |
struct | QMetaObject |
The QMetaObject class contains meta-information about Qt objects.
\inmodule QtCore
The Qt \l{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: \list
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().
Definition at line 164 of file qobjectdefs.h.
typedef void* Connection::* QMetaObject::RestrictedBool |
Definition at line 463 of file qobjectdefs.h.
enum QMetaObject::Call |
Enumerator | |
---|---|
InvokeMetaMethod | |
ReadProperty | |
WriteProperty | |
ResetProperty | |
CreateInstance | |
IndexOfMethod | |
RegisterPropertyMetaType | |
RegisterMethodArgumentMetaType | |
BindableProperty |
Definition at line 386 of file qobjectdefs.h.
QMetaObject::~Connection | ( | ) |
|
static |
|
static |
Definition at line 3987 of file qobject.cpp.
Definition at line 381 of file qmetaobject.cpp.
Returns true
if the signal and method arguments are compatible; otherwise returns false
.
Both signal and method are expected to be normalized.
Definition at line 1227 of file qmetaobject.cpp.
|
static |
Returns true
if the signal and method arguments are compatible; otherwise returns false
.
Definition at line 1249 of file qmetaobject.cpp.
QMetaClassInfo QMetaObject::classInfo | ( | int | index | ) | const |
Returns the meta-data for the item of class information with the given index.
Example:
Definition at line 1204 of file qmetaobject.cpp.
int QMetaObject::classInfoCount | ( | ) | const |
Returns the number of items of class information in this class.
Definition at line 587 of file qmetaobject.cpp.
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.
Definition at line 497 of file qmetaobject.cpp.
const char * QMetaObject::className | ( | ) | const |
Returns the class name.
Definition at line 335 of file qmetaobject.cpp.
|
inlinenoexcept |
Definition at line 467 of file qobjectdefs.h.
QMetaObject::Connection | ( | const Connection & | other | ) |
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:
Let's assume our object has a child object of type {QPushButton} with the \l{QObject::objectName}{object name}
{button1}. The slot to catch the button's
{clicked()} signal would be:
If object itself has a properly set object name, its own signals are also connected to its respective slots.
Definition at line 3614 of file qobject.cpp.
QMetaMethod QMetaObject::constructor | ( | int | index | ) | const |
Returns the meta-data for the constructor with the given index.
Definition at line 1116 of file qmetaobject.cpp.
int QMetaObject::constructorCount | ( | ) | const |
Returns the number of constructors in this class.
Definition at line 515 of file qmetaobject.cpp.
|
static |
\internal
Disconnect a single signal connection. If QMetaObject::connect() has been called multiple times for the same sender, signal_index, receiver and method_index only one of these connections will be removed.
Definition at line 3464 of file qobject.cpp.
QMetaEnum QMetaObject::enumerator | ( | int | index | ) | const |
Returns the meta-data for the enumerator with the given index.
Definition at line 1146 of file qmetaobject.cpp.
int QMetaObject::enumeratorCount | ( | ) | const |
Returns the number of enumerators in this class.
Definition at line 549 of file qmetaobject.cpp.
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.
Definition at line 455 of file qmetaobject.cpp.
int QMetaObject::indexOfClassInfo | ( | const char * | name | ) | const |
Finds class information item name and returns its index; otherwise returns -1.
Definition at line 1094 of file qmetaobject.cpp.
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().
Definition at line 685 of file qmetaobject.cpp.
int QMetaObject::indexOfEnumerator | ( | const char * | name | ) | const |
Finds enumerator name and returns its index; otherwise returns -1.
Definition at line 1024 of file qmetaobject.cpp.
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().
Definition at line 701 of file qmetaobject.cpp.
int QMetaObject::indexOfProperty | ( | const char * | name | ) | const |
Finds property name and returns its index; otherwise returns -1.
Definition at line 1062 of file qmetaobject.cpp.
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().
Definition at line 766 of file qmetaobject.cpp.
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.
Definition at line 813 of file qmetaobject.cpp.
|
noexcept |
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.
Definition at line 357 of file qmetaobject.cpp.
|
inlinestatic |
Definition at line 365 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 352 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 330 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 341 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 278 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 244 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 261 of file qobjectdefs.h.
|
static |
\threadsafe
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:
\list
The return value of the member function call is placed in ret. 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, and val9) to the member function.
QGenericArgument and QGenericReturnArgument are internal helper classes. Because signals and slots can be dynamically invoked, you must enclose the arguments using the Q_ARG() and Q_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.
You only need to pass the name of the signal or slot to this function, not the entire signature. For example, to asynchronously invoke the \l{QThread::quit()}{quit()} slot on a QThread, use the following code:
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
call qRegisterMetaType() to register the data type before you call invokeMethod().
To synchronously invoke the compute(QString, int, double)
slot on some arbitrary object obj
retrieve its return value:
If the "compute" slot does not take exactly one QString, one int and one double in the specified order, the call will fail.
Definition at line 1446 of file qmetaobject.cpp.
|
inlinestatic |
Definition at line 306 of file qobjectdefs.h.
|
inlinestatic |
Definition at line 318 of file qobjectdefs.h.
QMetaType QMetaObject::metaType | ( | ) | const |
Definition at line 400 of file qmetaobject.cpp.
QMetaMethod QMetaObject::method | ( | int | index | ) | const |
Returns the meta-data for the method with the given index.
Definition at line 1129 of file qmetaobject.cpp.
int QMetaObject::methodCount | ( | ) | const |
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 QStringList containing the methods specific to a given class:
Definition at line 533 of file qmetaobject.cpp.
int QMetaObject::methodOffset | ( | ) | const |
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 QObject has the deleteLater() slot and a destroyed() signal).
Definition at line 433 of file qmetaobject.cpp.
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 |
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 \nullptr 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.
Definition at line 240 of file qmetaobject.cpp.
|
static |
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.
Definition at line 1325 of file qmetaobject.cpp.
|
static |
Normalizes a type.
See QMetaObject::normalizedSignature() for a description on how Qt normalizes.
Example:
Definition at line 1309 of file qmetaobject.cpp.
|
inline |
Definition at line 464 of file qobjectdefs.h.
Connection& QMetaObject::operator= | ( | const Connection & | other | ) |
QMetaProperty QMetaObject::property | ( | int | index | ) | const |
Returns the meta-data for the property with the given index. If no such property exists, a null QMetaProperty is returned.
Definition at line 1164 of file qmetaobject.cpp.
int QMetaObject::propertyCount | ( | ) | const |
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 QStringList containing the properties specific to a given class:
Definition at line 571 of file qmetaobject.cpp.
int QMetaObject::propertyOffset | ( | ) | const |
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 QObject has the name() property).
Definition at line 476 of file qmetaobject.cpp.
|
inlinestaticconstexpr |
Definition at line 401 of file qobjectdefs.h.
|
inline |
Returns the meta-object of the superclass, or \nullptr if there is no such object.
Definition at line 477 of file qobjectdefs.h.
|
inlinenoexcept |
QMetaProperty QMetaObject::userProperty | ( | ) | const |
Returns the property that has the USER
flag set to true.
Definition at line 1183 of file qmetaobject.cpp.
|
friend |
Definition at line 451 of file qobjectdefs.h.
|
friend |
Definition at line 449 of file qobjectdefs.h.
|
friend |
Definition at line 450 of file qobjectdefs.h.
|
friend |
Definition at line 443 of file qobjectdefs.h.
struct QMetaObject::Data QMetaObject::d |