CopperSpice API  1.9.1
Meta Object System

The meta object system provides the signal and slot mechanism for communication between objects, runtime type information, and the dynamic property system. The QObject class is the base class for objects which use the meta object system. To use the meta object system you must add the CS_OBJECT() macro inside the private section of the class declaration.

In addition to providing the Signals and Slots mechanism for communication between objects the meta object system provides the following additional features.

  • QObject::metaObject() returns the corresponding meta object for that class
  • QMetaObject::className() returns the class name as a string at runtime
  • QObject::inherits(const QString &className) returns whether an object inherits from className
  • QObject::tr() translate strings for Internationalization
  • QObject::setProperty() and QObject::property() dynamically set and get properties by name
  • QMetaObject::newInstance() constructs a new instance of the specified class

While it is possible to use QObject as a base class without the CS_OBJECT() macro and without meta object code, neither signals, slots nor the other features described here will be available if the CS_OBJECT() macro is not used. This means the QMetaObject::className() will not return the actual name of your class, but the class name of this ancestor.

We recommend all subclasses of QObject use the CS_OBJECT() macro regardless of whether or not they actually use signals, slots, and properties.

See also
QMetaObject, Property System, Signals and Slots