Introspection implementation in C ++ (Qt)

I was wondering if anyone could explain the following to me. I am going to conduct a test in relation to Qt, and the sample questions are rather ambiguous. One of the questions:

Qt implements introspection in C ++:

a. Automatically detect each class as a QObject.

b. Defining meta objects that can call themselves in the QObject class.

from. Defining a meta object associated with each QObject.

I know that in order to have introspection, you must have inherited QObject (it also implements signals and slots), and using the macro Q_OBJECT makes it so that it can be replaced with MOC. I have a feeling that this can be any of these answers, but I want someone to clarify. I think this is A, but I could be wrong.

Any help is greatly appreciated.

+4
source share
3 answers

Qt implements introspection by storing information about each derived class QObject(and what the macro has Q_OBJECT) in QMetaObject(read here ). QMetaObjectcreated by the preliminary processor moc.

I would not consider any of your three options:

  • a is not true.
  • b does not make sense as a sentence.
  • c is correct if you add a subclass at the end.

There is a bit more information here regarding moc.

+2
source

( ) Qt , , Java .NET.

QObject QMetaObject, , - QMetaType.

, , QPen QSize, "" , .. , , Q_DECLARE_METATYPE.

, QVariant . , ( ), QVariant, .

"", , - . , . , .

0

: C.

  • A: Qt QObject ( );
  • B: , , , ++ , ...
  • C: . Q_OBJECT, MOC (Qt Meta Object Compiler), QMetaObject ++ . QObject QMetaObject QMetaObject, .
-1

All Articles