PDA

View Full Version : Q_OBJECT macro issue



kandalf
23rd January 2007, 18:50
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:


//GeneratorMainWindow.h
#ifndef GENERATORMAINWINDOW_H
#define GENERATORMAINWINDOW_H

#include <QMainWindow>
#include "GeneratorMainWindowUI.h"


class GeneratorMainWindow : private Ui::GeneratorMainWindowUI, public QMainWindow
{
Q_OBJECT
public:
GeneratorMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);

private slots:
void showAddFieldDialog();
};

#endif


//GeneratorMainWindow.cpp

#include "GeneratorMainWindow.h"
#include "AddCustomFieldDialog.h"

GeneratorMainWindow::GeneratorMainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
setupUi(this);
mainSplitter->setStretchFactor(1,1);
connect( addButton, SIGNAL(clicked()), this, SLOT(showAddFieldDialog()) );
}

void GeneratorMainWindow::showAddFieldDialog()
{
AddCustomFieldDialog *addDialog = new AddCustomFieldDialog(this);
addDialog->show();
}


Any ideas?

Thanx a lot in advance.

jpn
23rd January 2007, 19:39
The class inheriting QObject must be first in the inheritance list, so try switching the order:


class GeneratorMainWindow : public QMainWindow, private Ui::GeneratorMainWindowUI
{
...
};

Rerun qmake after the modification has been done.

kandalf
23rd January 2007, 20:28
The class inheriting QObject must be first in the inheritance list, so try switching the order:


class GeneratorMainWindow : public QMainWindow, private Ui::GeneratorMainWindowUI
{
...
};

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.