Qt Linker Error: "undefined reference to vtable"

Thomas picture Thomas · Mar 31, 2010 · Viewed 36.3k times · Source

This is my header:

#ifndef BARELYSOCKET_H
#define BARELYSOCKET_H

#include <QObject>
//! The First Draw of the BarelySocket!

class BarelySocket: public QObject
{
    Q_OBJECT

public:
    BarelySocket();
public slots:
    void sendMessage(Message aMessage);
signals:
    void reciveMessage(Message aMessage);

private:
    //   QVector<Message> reciveMessages;
};

#endif // BARELYSOCKET_H

This is my class:

#include <QTGui>
#include <QObject>
#include "type.h"
#include "client.h"
#include "server.h"

#include "barelysocket.h"

BarelySocket::BarelySocket()
{
    //this->reciveMessages.clear();
    qDebug("BarelySocket::BarelySocket()");
}

void BarelySocket::sendMessage(Message aMessage)
{
}

void BarelySocket::reciveMessage(Message aMessage)
{
}

I get a Linker error:

undefined reference to 'vtable for BarelySocket'
  • This implies that I have a virtual method not implemented. But there are no virtual methods in my class.
  • I commented out the vector thinking that it was the cause, but the error did not go away.
  • The Message is a complex struct, but even using int instead did not fix things.

Answer

Michael picture Michael · Sep 6, 2010

Any time you add a new call to the Q_OBJECT macro, you need to run qmake again. The vtables issue you're referring to is directly related to that.

Just run qmake and you should be good to go assuming there are no other issues in your code.