PDA

View Full Version : QObject inheriting class - problems with vtable and moc generation



ComServant
30th July 2011, 20:25
Despite all my attempts, and reading over many forum posts, I'm still getting the infamous 'undefined reference to 'vtable for GameStructure'' error.

I've had this error before, and resolved it multiple times in the past, but this time I can't figure it out. Despite calling qmake, moc_GameStructure.cpp is not getting generated.

Here's my code:


#ifndef GAMESTRUCTURE_H
#define GAMESTRUCTURE_H

#include <QObject>

class GameStructure : public QObject
{
Q_OBJECT
public:
explicit GameStructure(QObject *parent = 0);

signals:

public slots:
void testSlot();
};

#endif // GAMESTRUCTURE_H


#include "GameStructure.h"

GameStructure::GameStructure(QObject *parent) :
QObject(parent)
{

}


void GameStructure::testSlot()
{

}

qmake does not generate the moc file for GameStructure, even though it does for another class in the same project. I've 'Rebuilt All', and 'Clean All' three hundred and seventy one times and counting. :p

The exact error message is: "undefined reference to 'vtable for GameStructure'", which appears twice, followed by: "collect2: ld returned 1 exit status"

Am I missing some pure virtual function that QObject declares that I must define when inheritting QObject directly? I just care about the signal-and-slot features about QObject, none of the rest of it matters to me for this class.

SixDegrees
30th July 2011, 21:00
Make sure your source files are properly assigned to the correct HEADER and SOURCES variables in your .pro file.

ComServant
30th July 2011, 22:16
Oh, wow. Missed that.

But now I'm getting the, "Warning: No relevant classes found. No output generated." warning.
The moc file is now created, but empty.

The class does inherit from QObject ("class GameStructure : public QObject"), QObject is included (#include <QObject>),
it does use the Q_OBJECT macro as the first line of the class definition, and it does have a slot as part of the definition.

wysota
31st July 2011, 00:30
Is the code you posted the EXACT code you have?