PDA

View Full Version : Problems with MOC, vtable error



dajunior
5th April 2015, 22:09
I read similar threads but they didn't help me.
What's wrong with my code?
the file is included in the pro file.
Anyway there are errors about vtable...

#ifndef CUBE_H
#define CUBE_H

#include <QObject>

class cube: public QObject
{
Q_OBJECT

public:
explicit cube(QObject *parent=0)
{
for(int i=0; i<9; i++)
{
front[i]=Qt::white;
back[i]=Qt::yellow;
up[i]=Qt::green;
down[i]=Qt::blue;
left[i]=Qt::red;
right[i]=Qt::magenta;
}
}

~cube()
{
}

public:
void draw(QPainter & painter);

void moveFront();
void moveBack();
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
void moveFrontInverted();
void moveBackInverted();
void moveUpInverted();
void moveDownInverted();
void moveLeftInverted();
void moveRightInverted();
void rotateSide(Qt::GlobalColor side[9]);
void rotateSideInverted(Qt::GlobalColor side[9]);
void rotateRibs(Qt::GlobalColor &a1, Qt::GlobalColor &a2, Qt::GlobalColor &a3, Qt::GlobalColor &b1, Qt::GlobalColor &b2, Qt::GlobalColor &b3, Qt::GlobalColor &c1, Qt::GlobalColor &c2, Qt::GlobalColor &c3, Qt::GlobalColor &d1, Qt::GlobalColor &d2, Qt::GlobalColor &d3);
void rotateRibsInverted(Qt::GlobalColor &a1, Qt::GlobalColor &a2, Qt::GlobalColor &a3, Qt::GlobalColor &b1, Qt::GlobalColor &b2, Qt::GlobalColor &b3, Qt::GlobalColor &c1, Qt::GlobalColor &c2, Qt::GlobalColor &c3, Qt::GlobalColor &d1, Qt::GlobalColor &d2, Qt::GlobalColor &d3);

private:
Qt::GlobalColor front[9];
Qt::GlobalColor back[9];
Qt::GlobalColor up[9];
Qt::GlobalColor down[9];
Qt::GlobalColor left[9];
Qt::GlobalColor right[9];

signals:
void changed();
};

#endif // CUBE_H

Added after 37 minutes:

the problem is with the QtCreator, because the code works well being compiling manually with qmake and make utilities.
What can be wrong with the QtCreator?

anda_skoa
5th April 2015, 23:10
vtable errors usually mean you added the Q_OBJECT macro to a header after adding the header to the project.
Which means qmake did not yet see the macro and has not created a rule for running MOC on the classes declared in that header.

You can just manually trigger a qmake run via the respective entry in the Build menu.

Cheers,
_

dajunior
6th April 2015, 08:02
Oh thank you, but I don't understand.
Of course I added the header with no Q_OBJECT first. How could I know that I'd need it?
Also I found another problem. I couldn't compile this line using QtCreator:
QObject::connect(&MyCube, &cube::changed, MyCubeWidget, static_cast<void(CubeWidget::*)()>(&CubeWidget::update));

So I was forced to use old style:
QObject::connect(&MyCube, SIGNAL(changed()), MyCubeWidget, SLOT(update()));

But when I tried to compile my project manually using qmake and make I found that the first variant was okey. Why is it so? Why QtCreator acts so strange?
I'm a bit disappointed with QtCreator honestly...

anda_skoa
6th April 2015, 09:59
Oh thank you, but I don't understand.
Of course I added the header with no Q_OBJECT first. How could I know that I'd need it?

Well, the only reason not to add Q_OBJECT is that the class does not inherit QObject or a derived class.
If the inheritance is changed later on, then the effect you've described can happen.

Which, as I explained above, can be easily remidied by running qmake once.



Also I found another problem. I couldn't compile this line using QtCreator:
QObject::connect(&MyCube, &cube::changed, MyCubeWidget, static_cast<void(CubeWidget::*)()>(&CubeWidget::update));

What was the error you were getting?
Do you have overloaded update() functions, i.e. why is there a need for the cast?

[QUOTE=dajunior;275337]
But when I tried to compile my project manually using qmake and make I found that the first variant was okey.
[/quote
Are you running the same qmake?

Cheers,
_