CopperSpice Overview
MetaObject System

This section details the structure of the CopperSpice MetaObject System.

  • QObject

    • QObject::connect() can use standard string values for Signal and Slot parameters
    • QObject::connect() can use standard string values for Signal and a lambda for the Slot
    • QObject::connect() can use a method pointer for the Signal and Slot parameters
    • QObject::connect() can use a method pointer for the Signal and a lambda for the Slot
    • When using method pointers in QObject::connect() with an overloaded signal, ensure the method pointer is cast to a data type which exactly matches the class containing the signal
    • If QObject::connect() is called with a method pointer then QObject::disconnect() must also be passed a method pointer unless the method was registered as a slot
    • CopperSpice supports the Qt 5 method QObject::isSignalConnected(const QMetaMethod &signal) const
    • The variable staticMetaObject was changed to a method in CopperSpice.
    Library Method
    Qt QPushButton::staticMetaObject
    CopperSpice QPushButton::staticMetaObject()   
    • CopperSpice is consistent with Qt in that QObjects should not be declared as const.

      The receiver of a signal can not be const because slots are allowed to modify the receiver's data. The following code will compile, but is not permitted as the results are undefined:

      const MyClass temp;
      const QPushButton button;
    • The signature of QObject::connectNotify() has changed as indicated:
    Library Method
    Qt 4 QObject::connectNotify(const char * signalName)
    Qt 5 QObject::connectNotify(const QMetaMethod &signal)
    CopperSpice QObject::connectNotify(const QMetaMethod &signal) const
  • QMetaClassInfo
    • No changes


  • QMetaEnum
    • Unresolved Enum Values will generate a run time error when your application is started
    • CS_ENUMS() must appear before CS_REGISTER_ENUMS()
    • Enum expressions can be
      • References to values in the same enum
      • OR operator
      • Left Shift operator


  • QMetaMethod
    • QMetaMethod::parameterNames() returns 'un_named_arg', when no method argument name is declared
    • QMetaMethod::invoke() no longer restricted to 10 arguments
    • QMetaMethod::invoke() now supports any data type, refer to Argument Syntax


  • QMetaObject
    • QMetaObject is a structure in Qt 4 and Qt 5, it is implemented as a class in CopperSpice
    • CopperSpice supports the Qt 5 overloaded method
      QMetaObject::checkConnectArgs(const QMetaMethod &signal, const QMetaMethod &method)
    • QMetaObject::invokeMethod() is no longer restricted to 10 arguments
    • QMetaObject::invokeMethod() now supports any data type, refer to Argument Syntax
    • QMetaObject::normalizedSignature() can not be passed a signature which includes a return type


  • QMetaProperty
    • There are no limitations on data types

      • QMap is no longer restricted to only QMap<QString, QVariant>, any data types may be used
      • QList is no longer restricted to only QList<QVariant>, any data types may be used
      • Function pointers are supported as the value of a property
      • Method pointers are supported as the value of a property


  • QMetaType
    • Added ids for QJson classes


Argument Syntax

The old Q_ARG() macro did not support passing a value when the data type contained a comma. Before CopperSpice, a complex data type like QHash<QString, int> could not be used with this macro or as a Signal or Slot argument.

The implementation of invokeMethod() was enhanced in CopperSpice to allow passing data of any complex data type. The following two examples have the same meaning. The second example shows how to pass a QString using the CSArgument class instead of the Q_ARG() macro.

QMap<QString,bool> data;
// example 1
metaObject->invokeMethod(object,"callable_method", Q_ARG(QString, "some string"), data);
// example 2
QString myString = "some string";
metaObject->invokeMethod(object,"callable_method", CSArgument<QString>(myString), data);

Signals & Slots

The following list shows application errors which are now detected at compile time.

  • Connect()
    • Error Message: (CopperSpice) QObject::Connect() invalid, Signal was not a child class of Sender
      Means: Verify the Sender and Signal parameters for Connect() agree

    • Error Message: (CopperSpice) QObject::Connect() invalid, Slot was not a child class of Receiver
      Means: Verify the Receiver and Slot parameters for Connect() agree

    • Error Message: (CopperSpice) QObject::Activate() invalid, Signal parameter mismatch
      Means: Verify the Signal parameters are specified in CS_SIGNAL_1 and CS_SIGNAL_2