Q. What is moc in Qt?
A: moc stand for Meta-object-compiler.
moc is the program that handles Qt’s C++ extensions.
The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes.
Meta Object code is required for the following:
Signals and slots mechanism
run time type information
dynamic property system
Limitaion:
1. moc can not handle all features of C++ . for example , class templates cannot have signals or slots.
2.moc does not expand macros, so you for example cannot use a macro to declare a signal/slot or use one to define a base class for a QObject.
3.moc doesn't expand #defines, type macros that take an argument will not work in signals and slots.
Here is an illegal example
#ifdef ultrix
#define SIGNEDNESS(a) unsigned a
#else
#define SIGNEDNESS(a) a
#endif
class Whatever : public QObjects
{
Q_OBJECT
signals:
void someSignal(SIGNEDNESS(int));
};
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment