Menu
Home
Log in / Register
 
Home arrow Computer Science arrow Learn BlackBerry 10 App Development
< Prev   CONTENTS   Next >

Qt Object Model

I very briefly mentioned the Qt object model when I presented the signals and slots mechanism in Chapter 1. The model extends standard C++ with runtime type introspection and metatype information, among other things.

The Qt object model adds the following features to standard C++ (your class must inherit from

QObject and declare thee Q_OBJECT macro):

n Runtime type introspection using the QMetaObject class.

n A dynamic property system giving you the possibility to add properties at runtime to an instance of a QObject class.

n The signals and slots notification and interobject communication mechanism.

n A form of memory management using parent-child relationships. At any point you can set a child object's parent (this will effectively add the object to the parent's list of children). The parent will then take ownership of the child object and whenever the parent is deleted, it will also take care of deleting all of its children.

Meta-Object Compiler (MOC)

I already mentioned the MOC tool in Chapter 1, but I will do a quick recap here. The MOC parses a C++ header file and if it finds a class declaration containing the Q_OBJECT macro, generates additional code in order to add runtime introspection, signals and slots, and dynamic properties to that class (note that you have also encountered other macros such as Q_PROPERTY, Q_ENUMS and

Q_INVOKABLE used by the MOC compiler in order to “enrich” a class's functionality). Note that when using the Momentics IDE, you don't need to take any additional steps to use the MOC tool, which is automatically called during the build process; it will scan all the header files located in the source folder of your project. (You can see this happening if you carefully inspect the console view during the build phase: if the class declaration is in a header file called MyClass.h, the MOC generated output will be created in moc_MyClass.cpp and dropped in a folder of your project tree. On the Mac, it's a hidden folder.)

QObject

QObject is essential in Qt/Cascades programming because it implements most of the functionality at the heart of the Qt object model discussed in the previous section. You have already informally encountered the QObject::connect() method in Chapter 1 in order to connect signals to slots.

The purpose of this section is to give you additional details by reviewing other important QObject

methods.

 
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
 
Subjects
Accounting
Business & Finance
Communication
Computer Science
Economics
Education
Engineering
Environment
Geography
Health
History
Language & Literature
Law
Management
Marketing
Philosophy
Political science
Psychology
Religion
Sociology
Travel