QObject is the base class for all Qt classes, Q_OBJECT macro is used to enable meta-object features in classes and finally moc is a preprocessor that changes.
Q_OBJECT requires the class to be subclass of QObject. This macro is necessary for the class to declare its signals/slots and to use Qt meta-object system. If Meta.
Notice that the Q_OBJECT macro is mandatory for any object that implements signals, slots or properties. You also need to run the Meta Object Compiler on the.
Be aware, this might be platform dependent and it might change depending on the version of QT. Sign up using Email and Password. What is the purpose of this preprocessor macro? Active 7 months ago. Email Required, but never shown. What posts should be escalated to staff using [status-review], and how do I…. Podcast New tools for new times. Your code will be subtly broken when the macro is absent, and just because it happens to compile doesn't make it OK. But it will be quietly ignored in any other classes - it just adds to the build time. Andres Andres 17 3 3 bronze badges. Related Hot Network Questions. We're switching to CommonMark. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system. Why do all Qt objects need this macro? Stack Overflow works best with JavaScript enabled.{/INSERTKEYS}{/PARAGRAPH} ApproachingDarknessFish Bob Zhang Bob Zhang 53 1 1 silver badge 4 4 bronze badges. You can see it is not just a tag for the moc compiler. This generated source file is either include'd into the class's source file or, more usually, compiled and linked with the class's implementation. Reinstate Monica Active Oldest Votes. The Overflow Blog. {PARAGRAPH}{INSERTKEYS}Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more. Ask Question. It also pollutes your class's namespace with QObject -specific members. Asked 10 years, 9 months ago. See more linked questions. What could Stack Exchange Inc do to make moderators who've recently resigned…. Sign up using Facebook. So whether the macro should appear in under the private , protected , or public specifiers is irrelevant — it's just convention to place it at the head of the class. That's wrong. The macro is useful, but neither limited to nor required for gui-classes. Arne Arne 6, 4 4 gold badges 37 37 silver badges 57 57 bronze badges. Sign up or log in Sign up using Google. Question feed. Stu Mackellar Stu Mackellar Martin Beckett Martin Beckett It can lead to some perplexing behavior, so it's a bad idea. Linked 1. In gcc with -E you can see expanded macros. Viewed 72k times. Why the developers who use Rust love it so much. Featured on Meta. Post as a guest Name.