PDA

View Full Version : Getting Errors When Try To Compile Two QObject Subclasses



JeffSturmann
12th October 2012, 03:26
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



#ifndef BANKFRAME_HPP
#define BANKFRAME_HPP

#include "All_Needed_Qt4_Headers.h"

/* This is the UIC compiled header with All the BankFrame UI widgets from the UI file. */
#include "BankFrameUI.hpp"

/* This is the MOC compiled header of the LoginFrame class, declared later here. */
#include "LoginFrame_moc.hpp"

class BankFrame : public QFrame, private Ui::BankFrame
{
private:

private slots:

on_createAccountBT_Pressed(void);
on_doLogonBT_Pressed(void);

public:

BankFrame(void)
{
setupUi((QFrame*)this);
QObject::connect(createAccBT, SIGNAL(clicked()), this, SLOT(on_createAccountBT_Pressed()));
QObject::connect(doLogonBT, SIGNAL(clicked()), this, SLOT(on_doLogonBT_Pressed()));
}

~BankFrame(){}
};

#endif



Now, the problematic class, LoginFrame.hpp - The class used by BankFrame to show a window to do Logon in a Bank System.


#ifndef LOGINFRAME_HPP
#define LOGINFRAME_HPP

#include "All_Needed_Qt4_Headers_Again.h"

/* This is the UIC compiled header with All the LoginFrame widgets from the UI file. */
#include "LoginFrameUI.hpp"

class LoginFrame : public QFrame, private Ui::LoginFrame
{
private:

private slots:

void on_logonBT_Pressed(void);

public:

LoginFrame(void)
{
setupUi((QFrame*)this);
QObject::connect(logonBT, SIGNAL(clicked()), this, SLOT(on_logonBT_Pressed()));
}

~LogonFrame(){}
};

#endif



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?

ChrisW67
12th October 2012, 04:36
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.

JeffSturmann
12th October 2012, 20:30
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.

ChrisW67
12th October 2012, 22:42
I solved my problem. ... the same errors appears.
:confused: So did you solve it or not?