CopperSpice API  1.9.1
QMetaObject Class Referenceabstract

The QMetaObject class stores meta information about objects. More...

Public Methods

virtual QMetaClassInfo classInfo (int index) const = 0
 
virtual int classInfoCount () const = 0
 
int classInfoOffset () const
 
virtual const QStringclassName () const = 0
 
virtual QMetaMethod constructor (int index) const = 0
 
virtual int constructorCount () const = 0
 
virtual QMetaEnum enumerator (int index) const = 0
 
virtual int enumeratorCount () const = 0
 
int enumeratorOffset () const
 
int indexOfClassInfo (const QString &name) const
 
int indexOfConstructor (const QString &constructor) const
 
int indexOfEnumerator (const QString &name) const
 
int indexOfMethod (const QString &method) const
 
int indexOfProperty (const QString &name) const
 
int indexOfSignal (const QString &signal) const
 
int indexOfSlot (const QString &slot) const
 
virtual QMetaMethod method (int index) const = 0
 
virtual int methodCount () const = 0
 
int methodOffset () const
 
template<class... Ts>
QObjectnewInstance (Ts...Vs) const
 
virtual QMetaProperty property (int index) const = 0
 
virtual int propertyCount () const = 0
 
int propertyOffset () const
 
virtual const QMetaObject * superClass () const = 0
 
QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) const
 
QString tr (const QString &text, const QString &comment=QString (), std::optional< int > numArg=std::optional< int >()) const
 
QMetaProperty userProperty () const
 

Static Public Methods

static bool checkConnectArgs (const QString &signal, const QString &method)
 
static void connectSlotsByName (QObject *object)
 
template<class... Ts>
static bool invokeMethod (QObject *object, const QString &member, CSArgument< Ts >...Vs)
 
template<class R , class... Ts>
static bool invokeMethod (QObject *object, const QString &member, CSReturnArgument< R > retval, CSArgument< Ts >...Vs)
 
template<class... Ts>
static bool invokeMethod (QObject *object, const QString &member, Qt::ConnectionType type, CSArgument< Ts >...Vs)
 
template<class R , class... Ts>
static bool invokeMethod (QObject *object, const QString &member, Qt::ConnectionType type, CSReturnArgument< R > retval, CSArgument< Ts >...Vs)
 
static QString normalizedSignature (const QString &method)
 
static QString normalizedType (const QString &type)
 

Detailed Description

The QMetaObject class stores meta information about objects.

The CopperSpice Meta Object System is responsible for the signals and slots inter-object communication mechanism, runtime type information, and the CopperSpice 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().

The most commonly used methods are shown below.

The index methods indexOfConstructor(), indexOfMethod(), indexOfEnumerator(), and indexOfProperty() map names of constructors, methods, enumerators, or properties to indexes in the meta object.

Classes can also have a list of name / value pairs of additional class information which is stored in QMetaClassInfo objects. The number of pairs is returned by classInfoCount() and single pairs are returned by classInfo(). You can search for pairs using the indexOfClassInfo() method.

See also
QMetaClassInfo, QMetaEnum, QMetaMethod, QMetaProperty, Meta Object System

Method Documentation

bool QMetaObject::checkConnectArgs ( const QString signal,
const QString method 
)
static

Returns true if the signal and method arguments are compatible, otherwise returns false. Both signal and method are expected to be normalized.

See also
normalizedSignature()
QMetaClassInfo QMetaObject::classInfo ( int  index) const
pure virtual

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

class MyClass : public QObject
{
CS_OBJECT(MyClass)
CS_CLASSINFO("author", "Ray Bradbury")
CS_CLASSINFO("url", "http://www.raybradbury.com/about.html")
public:
...
};
See also
classInfoCount(), classInfoOffset(), indexOfClassInfo()
int QMetaObject::classInfoCount ( ) const
pure virtual

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

See also
classInfo(), classInfoOffset(), indexOfClassInfo()
int QMetaObject::classInfoOffset ( ) const

Returns the class information offset for this class. If the class has no parent with class information the offset is 0, otherwise the offset is the sum of all the class information items in all parent classes.

See also
classInfo(), classInfoCount(), indexOfClassInfo()
const QString & QMetaObject::className ( ) const
pure virtual

Returns the class name.

See also
superClass()
void QMetaObject::connectSlotsByName ( QObject object)
static

This method searches recursively for all child objects of the specified object and creates a connection from any matching signal to the corresponding slot.

void on_<object name>_<signal name>(<signal parameters>);

For example, assume the given object has a child named myButton which is of type QPushButton. If you have a slot declared as shown below this method will create the connection automatically.

public:
CS_SLOT_1(Private, void on_myButton_clicked())
CS_SLOT_2(on_myButton_clicked)
See also
QObject::setObjectName()
QMetaMethod QMetaObject::constructor ( int  index) const
pure virtual

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

See also
constructorCount(), newInstance()
int QMetaObject::constructorCount ( ) const
pure virtual

Returns the number of constructors in this class.

See also
constructor(), indexOfConstructor()
QMetaEnum QMetaObject::enumerator ( int  index) const
pure virtual

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

See also
enumeratorCount(), enumeratorOffset(), indexOfEnumerator()
int QMetaObject::enumeratorCount ( ) const
pure virtual

Returns the number of enumerators in this class.

See also
enumerator(), enumeratorOffset(), indexOfEnumerator()
int QMetaObject::enumeratorOffset ( ) const

Returns the enumerator offset for this class. If the class has no parents with enumerators the offset is 0, otherwise the offset is the sum of all the enumerators in all parent classes.

See also
enumerator(), enumeratorCount(), indexOfEnumerator()
int QMetaObject::indexOfClassInfo ( const QString name) const

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

See also
classInfo(), classInfoCount(), classInfoOffset()
int QMetaObject::indexOfConstructor ( const QString constructor) const

Finds constructor and returns its index, otherwise returns -1. The constructor must be in normalized form as returned by normalizedSignature().

See also
constructor(), constructorCount(), normalizedSignature()
int QMetaObject::indexOfEnumerator ( const QString name) const

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

See also
enumerator(), enumeratorCount(), enumeratorOffset()
int QMetaObject::indexOfMethod ( const QString method) const

Finds method and returns its index, otherwise returns -1. The method must be in normalized form as returned by normalizedSignature().

See also
method(), methodCount(), methodOffset(), normalizedSignature()
int QMetaObject::indexOfProperty ( const QString name) const

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

See also
property(), propertyCount(), propertyOffset()
int QMetaObject::indexOfSignal ( const QString signal) const

Finds signal and returns its index, otherwise returns -1. The signal must be in normalized form, as returned by normalizedSignature(). This is the same as indexOfMethod() except it will return -1 if the method exists but is not a signal.

See also
indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset()
int QMetaObject::indexOfSlot ( const QString 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 is not a slot.

See also
indexOfMethod(), method(), methodCount(), methodOffset()
template<class... Ts>
bool QMetaObject::invokeMethod ( QObject object,
const QString member,
CSArgument< Ts >...  Vs 
)
static

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

template<class R , class... Ts>
bool QMetaObject::invokeMethod ( QObject object,
const QString member,
CSReturnArgument< R >  retval,
CSArgument< Ts >...  Vs 
)
static

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

template<class... Ts>
bool QMetaObject::invokeMethod ( QObject object,
const QString member,
Qt::ConnectionType  type,
CSArgument< Ts >...  Vs 
)
static

This overload can be used if the return value of the member is of no interest.

template<class R , class... Ts>
bool QMetaObject::invokeMethod ( QObject object,
const QString member,
Qt::ConnectionType  type,
CSReturnArgument< R >  retval,
CSArgument< Ts >...  Vs 
)
static

Invokes the member (a signal or a slot name) on the given object. 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 the given 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 is placed in retval. You must enclose the return value in a Q_RETURN_ARG() macro. Q_RETURN_ARG() takes a type name and a non-const reference. If the invocation is asynchronous there is no return value. You only need to pass the name of the signal or slot to this method not the entire signature. For example, to asynchronously invoke the animateClick() slot on a QPushButton, use the following code.

QMetaObject::invokeMethod(pushButton, "animateClick", Qt::QueuedConnection);

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.

QString retval;
QMetaObject::invokeMethod(object, "compute", Qt::DirectConnection, Q_RETURN_ARG(QString, retval), QString("sqrt"), 42, 9.7);
See also
Q_RETURN_ARG(), QMetaMethod::invoke()
QMetaMethod QMetaObject::method ( int  index) const
pure virtual

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

See also
methodCount(), methodOffset(), indexOfMethod()
int QMetaObject::methodCount ( ) const
pure virtual

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 CS_INVOKABLE() macro.

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

const QMetaObject * metaObject = obj->metaObject();
QStringList methods;
for(int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) {
methods << metaObject->method(i).signature();
}
See also
method(), methodOffset(), indexOfMethod()
int QMetaObject::methodOffset ( ) const

Returns the method offset for this class. The offset is the sum of all the methods in the class superclasses (which is always positive since QObject has the deleteLater() slot and a destroyed() signal).

See also
method(), methodCount(), indexOfMethod()
template<class... Ts>
QObject * QMetaObject::newInstance ( Ts...  Vs) const

Constructs a new instance of this class. Returns the new object or a nullptr if no suitable constructor is available. Only constructors that are declared with the CS_INVOKABLE() modifier are made available through the meta object system.

See also
constructor()
QString QMetaObject::normalizedSignature ( const QString method)
static

Normalizes the signature of the given method.

CopperSpice uses normalized signatures to decide whether a given signal and slot are compatible. Normalization reduces whitespace to a minimum, moves 'const' to the front where appropriate, removes 'const' from value types, and for a parameter replaces a const reference with a value.

QString str = "mySlot(int const &) const";
QString normalStr = QMetaObject::normalizedSignature(str); // returns "mySlot(int)"
See also
checkConnectArgs(), normalizedType()
QString QMetaObject::normalizedType ( const QString type)
static

Normalizes a data type.

QString normType = QMetaObject::normalizedType(" int const *"); // return "const int*"
See also
normalizedSignature()
QMetaProperty QMetaObject::property ( int  index) const
pure virtual

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

See also
propertyCount(), propertyOffset(), indexOfProperty()
int QMetaObject::propertyCount ( ) const
pure virtual

Returns the number of properties in this class, including the number of properties provided by each base class. The following example can be used to obtain a QStringList containing the properties specific to a given class.

const QMetaObject * metaObject = obj->metaObject();
QStringList properties;
for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
properties << metaObject->property(i).name();
}
See also
property(), propertyOffset(), indexOfProperty()
int QMetaObject::propertyOffset ( ) const

Returns the property offset for this class. The offset is the sum of all the properties in the class superclasses (which is always positive since QObject has the name() property).

See also
property(), propertyCount(), indexOfProperty()
const QMetaObject * QMetaObject::superClass ( ) const
pure virtual

Returns the meta object of the superclass or nullptr if there is no object.

See also
className()
QString QMetaObject::tr ( const char *  text,
const char *  comment = nullptr,
std::optional< int >  numArg = std::optional<int>() 
) const

Returns a translated version of text which is based on the given comment and the value of numArg for translations containing numbers. Returns the original given text if no translation is available.

QString QMetaObject::tr ( const QString text,
const QString comment = QString(),
std::optional< int >  numArg = std::optional<int>() 
) const

Returns a translated version of text which is based on the given comment and the value of numArg for translations containing numbers. Returns the original given text if no translation is available.

QMetaProperty QMetaObject::userProperty ( ) const

Returns the property where the USER flag is set to true. There should be only one property with the User flag set for a particular class and any parent classes.

See also
QMetaProperty::isUser()