Reputation: 155
I was wondering if somebody could clarify the following for me. I'm about to sit a test in relation to Qt and the sample questions are rather ambiguous. One of the questions are as follows:
Qt implements introspection in c++ by:
a. Automatically defining every class as QObject.
b. Defining meta objects that can call itself within a QObject class.
c. Defining a meta object associated to every QObject.
I know that to have introspection you must have QObject inherited (this also implements signals and slots), and using the Q_OBJECT macro makes it so that it can be replaced by the MOC. I have a feeling it could be anyone of these answers but I'd like somebody to clarify. I think it's A but I could be wrong.
Any help is greatly appreciated.
Upvotes: 4
Views: 2762
Reputation: 22346
Qt implements introspection through storing information about every QObject
derived class (and one that has the Q_OBJECT
macro) in a QMetaObject
(read here). The QMetaObject
is built by the moc
pre-processor.
I wouldn't consider any of your 3 options correct:
There's a little more information here regarding the moc
.
Upvotes: 3
Reputation: 60024
For efficiency (I guess), Qt does not derive each type from a common base, like Java or .NET do.
QObject exposes QMetaObject, that indeed allows a great deal of reflective programming, but the most fundamental meta programming tool is instead QMetaType.
Indeed some frequently used classes, like QPen, or QSize, that are 'root' objects, i.e. don't derive from anything at all, or your own classes, can be made available to metaprogramming via a macro, Q_DECLARE_METATYPE.
The purpose is to make available to QVariant construction and copy of generic objects. Then, since property exchange or method invoking are defined (at system level), using QVariant, such objects can be put to good use.
It's a 'mixed', efficient architecture, that sometime requires hardcoding the interface to literals. Generic interfaces are availabe, but only on binary data. Again, for efficiency.
Upvotes: 0
Reputation: 3448
The correct answer is C.
Upvotes: 0