Results 1 to 4 of 4

Thread: Getting Errors When Try To Compile Two QObject Subclasses

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting Errors When Try To Compile Two QObject Subclasses

    Hello partners,

    I´m having a lot of redefinition erros from MinGW when i try to compile two QObject subclasses named LoginFrame and BankFrame.

    Code above:


    BankFrame.hpp - "Main Window" (but QFrame) Class
    Qt Code:
    1. #ifndef BANKFRAME_HPP
    2. #define BANKFRAME_HPP
    3.  
    4. #include "All_Needed_Qt4_Headers.h"
    5.  
    6. /* This is the UIC compiled header with All the BankFrame UI widgets from the UI file. */
    7. #include "BankFrameUI.hpp"
    8.  
    9. /* This is the MOC compiled header of the LoginFrame class, declared later here. */
    10. #include "LoginFrame_moc.hpp"
    11.  
    12. class BankFrame : public QFrame, private Ui::BankFrame
    13. {
    14. private:
    15.  
    16. private slots:
    17.  
    18. on_createAccountBT_Pressed(void);
    19. on_doLogonBT_Pressed(void);
    20.  
    21. public:
    22.  
    23. BankFrame(void)
    24. {
    25. setupUi((QFrame*)this);
    26. QObject::connect(createAccBT, SIGNAL(clicked()), this, SLOT(on_createAccountBT_Pressed()));
    27. QObject::connect(doLogonBT, SIGNAL(clicked()), this, SLOT(on_doLogonBT_Pressed()));
    28. }
    29.  
    30. ~BankFrame(){}
    31. };
    32.  
    33. #endif
    To copy to clipboard, switch view to plain text mode 


    Now, the problematic class, LoginFrame.hpp - The class used by BankFrame to show a window to do Logon in a Bank System.
    Qt Code:
    1. #ifndef LOGINFRAME_HPP
    2. #define LOGINFRAME_HPP
    3.  
    4. #include "All_Needed_Qt4_Headers_Again.h"
    5.  
    6. /* This is the UIC compiled header with All the LoginFrame widgets from the UI file. */
    7. #include "LoginFrameUI.hpp"
    8.  
    9. class LoginFrame : public QFrame, private Ui::LoginFrame
    10. {
    11. private:
    12.  
    13. private slots:
    14.  
    15. void on_logonBT_Pressed(void);
    16.  
    17. public:
    18.  
    19. LoginFrame(void)
    20. {
    21. setupUi((QFrame*)this);
    22. QObject::connect(logonBT, SIGNAL(clicked()), this, SLOT(on_logonBT_Pressed()));
    23. }
    24.  
    25. ~LogonFrame(){}
    26. };
    27.  
    28. #endif
    To copy to clipboard, switch view to plain text mode 


    Yes, the slots are implemented (but empty for now) in the .CPP files.
    I tried to use the BankFrame in main() to test the layout, and i got
    a lot of meta object functions redefinition errors like this:

    - error: multiple definition of LoginFrame::qt_metacast(const char*)
    - error: multiple definition of LoginFrame::qt_metacall(QObject* ...
    - error: multiple definition of LoginFrame::qt_static_metacall(QObject* ...
    - error: multiple definition of LoginFrame::metaObject() const

    Note: I´m using CodeBlocks 10.15 , MinGW 4.6 and Qt 4.8.1


    Someone could tell me what´s the problem?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Getting Errors When Try To Compile Two QObject Subclasses

    Some or all of your header files are missing include guards at a guess.

    Edit: Actually, you do not normally include the moc output directly (line 10 first listing). The moc generated implementation is designed to be compiled and linked to your code, satisfying the declarations inserted by the (missing) Q_OBJECT macros. Since the items being complained about are moc generated I'd start there.
    Last edited by ChrisW67; 12th October 2012 at 04:42.

  3. #3
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting Errors When Try To Compile Two QObject Subclasses

    I solved my problem. Thank You.

    I really forgot the include guards and i was putting the MOC output files in a .HPP file instead a .CPP.
    If i put the MOC generates .CPP with the other files of project together (in the CodeBlocks project), the same errors appears.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Getting Errors When Try To Compile Two QObject Subclasses

    I solved my problem. ... the same errors appears.
    So did you solve it or not?

  5. The following user says thank you to ChrisW67 for this useful post:


Similar Threads

  1. QOBJECT and undefined reference to vtable errors
    By stargazer in forum Qt Programming
    Replies: 7
    Last Post: 25th April 2011, 05:29
  2. qwt vc++ compile errors
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 5th December 2009, 20:26
  3. create a Class inherits from two QObject subclasses
    By sabeesh in forum Qt Programming
    Replies: 17
    Last Post: 31st December 2007, 12:04
  4. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  5. Qt Compile Errors?
    By magikalpnoi in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2006, 22:18

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
  •  
Qt is a trademark of The Qt Company.