If I derive my class from QObject (or a subclass), the Qt documentation says that I have to put the Q_OBJECT macro into my class declaration.
It also says I need to “run the meta-object compiler” for my class.
I have no idea how to do this. Is this something I need to add to the .pro file? Do I need to edit the makefile? This seems overly complicated for a simple derived class.
I’m using Qt Creator.
EDIT:
Thanks for all the help. I discovered something very important: When I create a new class in Qt Creator, I have to specify “Inherits QWidget” as the type information, even if I’m already specifying a Qt widget as my base class (such as QTextEdit). It seems strange that Qt Creator couldn’t figure that out on its own, but that seems to solve my signal/slot and moc problems.
Qt uses the
moccompiler to produce its meta-object system (which is required for introspecting classes and allowing for signals/slots, amongst other things).By default,
qmakewill do the right thing when generating and compiling themoc_*.cppfiles.