See UNISA – Summary of 2010 Posts for a list of related UNISA posts. Continued from UNISA Chatter – Design patterns in C++ Part 6: Widgets … Validation and Regular Expressions using QT.
IMPORTANT POINT: It is important to emphasize that the intent of these posts are to share my learning's as I dig through the last three subjects of my part-time UNISA studies. The posts by no means promote concepts or technologies … they are pure information sharing for fellow students … although the highlight that we explore more technologies and concepts that we typically prefer 🙂
Today we explore QT’s implementation of the MetaObject Pattern, which provide information about properties and methods of a QObject.
|QT MetaObject Compiler||Also known as moc, generates the code that supports the reflection feature.|
Supports the following functions:
Using the typecast operator we can convert an expression from one type to another. The destination type (DestType) is derived from QObject, making the operator a downcast operator.
|Properties versus Getters/Setters||Getters and setters are faster and more efficient.
QObject Properties, however, are more generic.
|QVariant||Union wrapper for all the basic types and allowed Q_PROPERTY types. The struct delivers a rich interface for conversions and validations.|
An extension to the QOject, which delivers additional features:
Here is an extract from the assignment code I wrote to explore the above:
Textbook Header File (take note of lines 10 – 15) …
This results in the following code being generated and added to the resultant program …
Which we can analyze with a function such as …
Giving us this result …
Note that we have eight property macro methods, which are the four getters and the four setters we defined. We also have five properties … why five and not four? We have our four properties and the “name” property that is defined within QObject.
If you are working in Visual Studio 2010, as I am, you may want to look at the following information which is kind-of-related:
- Using Properties (C# Programming Guide) … http://msdn.microsoft.com/en-us/library/w86s7x04.aspx
- Attributes (C# and Visual Basic) … http://msdn.microsoft.com/en-us/library/z0w1kczw.aspx
- Accessing Attributes by Using Reflection (C# and Visual Basic) … http://msdn.microsoft.com/en-us/library/z919e8tw.aspx
- Reflection (C# and Visual Basic) … http://msdn.microsoft.com/en-us/library/ms173183.aspx
Yippee, next time we will look at more design patterns and summarize all of the patterns we have encountered during our UNISA adventure this year 🙂