Results 1 to 5 of 5

Thread: Don't understand Q_OBJECT

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Don't understand Q_OBJECT

    Hello.

    In the tutorials and examples everywhere I see that all class defintions start with the Q_OBJECT macro. I'm using Eclipse with Qt eclipse integration as IDE and rely on the existing functions to create new classes automaticly. None of them have the Q_OBJECT macro inside. So what is this macro about and how come my project still compiles and works right?

    Cruz

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Don't understand Q_OBJECT

    it's from Qt Assistant
    Q_OBJECT
    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    Cruz (19th January 2009)

  4. #3
    Join Date
    Dec 2008
    Location
    Czech
    Posts
    44
    Thanks
    2
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Don't understand Q_OBJECT

    if you put Q_OBJECT macro in your class declaration, than you tell the the moc (meta-object compiler) to run on this class, so check the moc tool in documentation to see what it does. The main thing it does is to deal with signals and slots. So if you want to use signal and slot in your class then you have to put Q_OBJECT macro there

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Don't understand Q_OBJECT

    Quote Originally Posted by radek.z View Post
    So if you want to use signal and slot in your class then you have to put Q_OBJECT macro there
    Actually this is not true. You have to place the macro if you want to declare new signals or slots. Using existing ones works fine without the macro.

  6. The following user says thank you to wysota for this useful post:

    Cruz (19th January 2009)

  7. #5
    Join Date
    Dec 2008
    Location
    Czech
    Posts
    44
    Thanks
    2
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Don't understand Q_OBJECT

    Yeah, that's right. I forgot to write that

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.