TheFuzz TheFuzz - 11 months ago 104
C++ Question

Undefined reference to vtable. Trying to compile a Qt project

I'm using Code::Blocks 8.02 and the mingw 5.1.6 compiler. I'm getting this error when I compile my Qt project:

C:\Documents and Settings\The
reference to `vtable for AddressBook'

File AddressBook.h:


#include <QWidget>

class QLabel;
class QLineEdit;
class QTextEdit;

class AddressBook : public QWidget

AddressBook(QWidget *parent = 0);

QLineEdit *nameLine;
QTextEdit *addressText;


File AddressBook.cpp:

#include <QtGui>
#include "addressbook.h"

AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;

QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;

QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameLine, 0, 1);
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
mainLayout->addWidget(addressText, 1, 1);

setWindowTitle(tr("Simple Address Book"));

Answer Source

Warning: Do not do this if you already have a .pro file - you'll lose it!

In order to automatically ensure that all moc cpp files are generated, you can get qmake to automatically generate a .pro file for you instead of writing one yourself.


qmake -project

in the project directory, and qmake will scan your directory for all C++ headers and source files to generate moc cpp files for.