Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:02:25+00:00 2026-05-16T21:02:25+00:00

The documentation states that: The Q_OBJECT macro must appear in the private section of

  • 0

The documentation states that:

The Q_OBJECT macro must appear in the
private section of a class definition
that declares its own signals and
slots or that uses other services
provided by Qt’s meta-object system.

But exactly what does that mean? On which QObject-derived classes can I safely omit it? Will problems arise if you omit Q_OBJECT on a QObject-derived class, and then inherit from that one? Basically I would like a little more information on when I can omit it from my Qt classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:02:26+00:00Added an answer on May 16, 2026 at 9:02 pm

    You should use the Q_OBJECT macro for any non-templated classes that derive from QObject.

    Besides signals and slots, the Q_OBJECT macro provides the meta object information that is associated with given class.

    As stated in the documentation:

    we strongly recommend that all subclasses of QObject use the Q_OBJECT macro regardless of whether or not they actually use signals, slots, and properties.

    Suppose we have the following class:

    class Class : public QObject {
    public:
      Class() {}
    };
    

    Without Q_OBJECT, the following metaobject system features (among others) will not work for Class:

    1. qobject_cast<Class>() – due to missing metadata

    2. QObject::tr() – due to missing metadata

    3. slots and invokables first declared in Class, when invoked or looked up by name – none of QMetaObject methods will work for these methods, neither will the Qt 4 connect – due to missing metadata

    4. signals – since moc won’t generate their implementations and the code won’t compile.

    You can omit it, of course, but if you ever use these features, you’ll need to remember to put the macro into the class’s declaration. This is a rather brittle practice and best avoided. The savings are not worth it. So, don’t wait – add the Q_OBJECT macro to every class that derives from QObject as a matter of coding policy.

    The Q_OBJECT macro should never be used on classes that don’t derive from QObject. To add invokables and properties to such classes, use the Q_GADGET macro instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Documentation states that 'handleResponseEnd' is called when the response has been completely received. http://twistedmatrix.com/documents/11.0.0/api/twisted.web.http.HTTPClient.html#handleResponseEnd
The jQuery documentation states that As of jQuery 1.6, the .attr() method returns undefined
The mongo documentation states that When a document is saved to a collection with
Windows Azure Caching is described as distributed, but the documentation states that the high
I'm aware that since MySQL 5, VARCHAR can have a length of up to
I am writing a Perl script that needs to extract some data from an
I followed the tutorial on the grails documentation was successfully able to create project
What is the maximum length of the alert text of an iOS push notification?
I am sending simple objects between processes using pipes with Python's multiprocessing module. The
Is it safe to use __syncthreads() in a block where I have purposefully dropped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.