Results 1 to 3 of 3

Thread: Q_OBJECT macro issue

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Q_OBJECT macro issue

    Hi guys, I'm facing a problem with Q_OBJECT macro.
    I've built a MainWindow with Designer, then I've declared a class which inherits from the class generated with moc from that .ui file and from QMainWindow.

    I've declared a private slot in this new class, with Q_OBJECT macro defined but, when I run make, I got the following error:

    In file included from moc_GeneratorMainWindow.cpp:10:
    GeneratorMainWindow.h:38:7: warning: no newline at end of file
    moc_GeneratorMainWindow.cpp:40: error: `staticMetaObject' is not a member of
    type `Ui::GeneratorMainWindowUI'
    moc_GeneratorMainWindow.cpp: In member function `virtual void*
    GeneratorMainWindow::qt_metacast(const char*)':
    moc_GeneratorMainWindow.cpp:57: error: 'class Ui::GeneratorMainWindowUI' has no
    member named 'qt_metacast'
    moc_GeneratorMainWindow.cpp: In member function `virtual int
    GeneratorMainWindow::qt_metacall(QMetaObject::Call , int, void**)':
    moc_GeneratorMainWindow.cpp:63: error: 'class Ui::GeneratorMainWindowUI' has no
    member named 'qt_metacall'
    make[1]: *** [moc_GeneratorMainWindow.o] Error 1
    make[1]: Leaving directory `/home/leonardo/svn/3WDGFGeneratorFrontEnd/src'
    make: *** [sub-src-make_default] Error 2
    And if I don't define Q_OBJECT macro I got no errors, but a custom slot is not defined.

    My code is this:
    Qt Code:
    1. //GeneratorMainWindow.h
    2. #ifndef GENERATORMAINWINDOW_H
    3. #define GENERATORMAINWINDOW_H
    4.  
    5. #include <QMainWindow>
    6. #include "GeneratorMainWindowUI.h"
    7.  
    8.  
    9. class GeneratorMainWindow : private Ui::GeneratorMainWindowUI, public QMainWindow
    10. {
    11. Q_OBJECT
    12. public:
    13. GeneratorMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    14.  
    15. private slots:
    16. void showAddFieldDialog();
    17. };
    18.  
    19. #endif
    20.  
    21.  
    22. //GeneratorMainWindow.cpp
    23.  
    24. #include "GeneratorMainWindow.h"
    25. #include "AddCustomFieldDialog.h"
    26.  
    27. GeneratorMainWindow::GeneratorMainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
    28. {
    29. setupUi(this);
    30. mainSplitter->setStretchFactor(1,1);
    31. connect( addButton, SIGNAL(clicked()), this, SLOT(showAddFieldDialog()) );
    32. }
    33.  
    34. void GeneratorMainWindow::showAddFieldDialog()
    35. {
    36. AddCustomFieldDialog *addDialog = new AddCustomFieldDialog(this);
    37. addDialog->show();
    38. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

    Thanx a lot in advance.
    Kandalf
    There's no place like ~

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q_OBJECT macro issue

    The class inheriting QObject must be first in the inheritance list, so try switching the order:
    Qt Code:
    1. class GeneratorMainWindow : public QMainWindow, private Ui::GeneratorMainWindowUI
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    Rerun qmake after the modification has been done.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Q_OBJECT macro issue

    Quote Originally Posted by jpn View Post
    The class inheriting QObject must be first in the inheritance list, so try switching the order:
    Qt Code:
    1. class GeneratorMainWindow : public QMainWindow, private Ui::GeneratorMainWindowUI
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    Rerun qmake after the modification has been done.
    Thanx a lot! That was all. I'm sorry for such a dumb question, I'm quite rusty with Qt, I've started to use it after a while.

    Cheers and thanx again.
    Kandalf
    There's no place like ~

Similar Threads

  1. Replies: 5
    Last Post: 22nd September 2006, 08:04

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.