CopperSpice Overview
|
The following table details the "Q_" macros which have been maintained or modified for CopperSpice. These changes expand functionality, provide more flexibility, and leverage new capabilities added in new versions of C++. The second column shows examples of how the macro or define might appear in your source code.
Define | Replacement | Description |
---|---|---|
Q_ARG | — | Unchanged in CS |
Q_CLASSINFO | CS_CLASSINFO("project", "KitchenSink") | |
Q_DECLARE_EXTENSION_INTERFACE | Remove, no replacement is required | Used internally with CsDesigner |
Q_DECLARE_FLAGS | Replacement Code | ➜ Example shown below |
Q_DECLARE_INTERFACE | CS_DECLARE_INTERFACE(ShapeInterface, "id") | |
Q_DECLARE_METATYPE | CS_DECLARE_METATYPE(TYPE) | |
Q_DECLARE_OPERATORS_FOR_FLAGS | — | Unchanged in CS |
Q_DECLARE_TR_FUNCTIONS | — | Unchanged in CS |
Q_DECLARE_TYPEINFO | Remove, no replacement is required | |
Q_DISABLE_COPY | — | Unchanged in CS |
Q_ENUMS | CS_ENUM(Spices) | |
[ Added macro ] | CS_REGISTER_ENUM( enum Spices {mint, basil}; ) | Enums must be registered when used as the value of a Property |
Q_EMIT | Not required | Signal & Slot declarations need to appear in the appropriate "public", "protected", or "private" specifier |
Q_FLAGS | CS_FLAG(Food_Enum, Food_Flag) | |
Q_GADGET | CS_GADGET(Ginger) | Class name must be passed |
Q_INTERFACES | CS_INTERFACES() | ➜ Example shown below |
Q_INVOKABLE | CS_INVOKABLE() | ➜ Example shown below |
Q_OBJECT | CS_OBJECT(Ginger) | Class name must be passed |
[ Added macro ] | CS_OBJECT_MULTIPLE(Ginger, QWidget) | Class name is passed as the first parameter For multiple inheritance the second parameter is the first parent class |
Q_OUTOFLINE_TEMPLATES | Removed since compilers after C++11 understand templates | |
Q_PROPERTY | CS_PROPERTY() | ➜ Example shown below |
Q_RETURN_ARG | — | Unchanged in CS |
Q_SCRIPT_DECLARE_QMETAOBJECT | — | Unchanged in CS |
Q_SIGNAL | CS_SIGNAL() | ➜ Example shown below |
Q_SIGNALS | Remove, place signal macros in a public section | All signals are registered individually |
Q_SLOT | CS_SLOT() | ➜ Example shown below |
Q_SLOTS | Remove, no replacement is required | All slots are registered individually or declared as a method |
[ Added macro ] | Overloaded Signals & Slots | ➜ Example shown below |
[ Added macro ] | CS_TAG("myTag", myMethod()) | Associates a tag with a method, refer to QMetaMethod::tag() |
Each property is declared using a separate macro. Any data type can be used for the property, including template data types like QMap<int, QString>.
A slot method only needs to be registered using the CS_SLOT macro when it is passed to connect() by name. If your code is only using method pointers in calls to connect(), simply declare your slots as you would declare any other method.
The valueChanged() signal for QSpinBox has two overloads. The following code shows how they are declared in CopperSpice.
When calling connect() using method pointers, the second parameter is a pointer to the signal and the fourth parameter is a pointer to the slot. If either the signal or the slot is overloaded additional syntax will be required so the compiler knows which overload to use. By adding the cs_mp_cast<int>
syntax the compiler now has enough information to select the correct overload. In this example the overload which accepts an int data type will be used.