CopperSpice Overview  1.5.2
CopperSpice MetaObject

CopperSpice MetaObject System

This section details the structure of the CopperSpice Meta Object 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.
    Qt usage QPushButton::staticMetaObject
    CopperSpice usage    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:
    Version 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

In Qt, the Q_ARG() macro does not support passing a value where the data type contains a comma. The implementation of invokeMethod() was enhanced in CopperSpice to allow passing data of any type. The following two examples are equivalent.

The second example shows a QString. Using this technique you can pass something like QHash<QString, int>, which was not possible before.


1 QMap<QString,bool> data;
2 
3 
4 // example 1
5 metaObject->invokeMethod(object,"callable_method", Q_ARG(QString, "some string"), data);
6 
7 
8 // example 2
9 QString myString = "some string";
10 metaObject->invokeMethod(object,"callable_method", CSArgument<QString>(myString), data);


Signals & Slots

The following list shows application errors which are 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