Results 1 to 2 of 2

Thread: When do I need Q_OBJECT?

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default When do I need Q_OBJECT?

    Hi.
    As I understand it, I need Q_OBJECT macro if I declare a class that should use signals and slots, and it should then also be derived from QObject?
    Like
    Qt Code:
    1. class Foo:public QObject{
    2. Q_OBJECT
    3. // etc.
    4. }
    To copy to clipboard, switch view to plain text mode 

    But if I derive from a class that already is derived from a QObject, like
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. MainWindow(QWidget * parent = 0);
    6. private:
    7. Ui::MainWindow ui;
    8. };
    To copy to clipboard, switch view to plain text mode 

    Is Q_OBJECT really needed here? I mean, there is nothing that uses signals/slots, the MainWindow constructor contains no signals emits or connects.
    I mean, the QMainWindow class is derived from QObject, doesn't it get the Q_OBJECT for that part?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: When do I need Q_OBJECT?

    Is Q_OBJECT really needed here? I mean, there is nothing that uses signals/slots, the MainWindow constructor contains no signals emits or connects.
    I mean, the QMainWindow class is derived from QObject, doesn't it get the Q_OBJECT for that part?
    You are right. The signals and slots from QMainWindow are available without using Q_OBJECT in your derived class.

    If you wanted to use new signal-slots in your derived class you would need Q_OBJECT. In your case you don't.


    have a look at this similar thread.
    http://www.qtcentre.org/forum/showth...light=q_object

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.