Tuesday, December 29, 2009

"undefined reference to vtable" Error

I'm having a very strange problem with Qt library (and C++ in general), this message:

undefined reference to vtable `...SomeClass...`

It frustrates me at first. I still don't know why it happens, but I know how to solve it in my case.

As an example, this code:

#include <QObject>
#include <stdio.h>

class HelloWorld : public QObject
    void done();

public slots:
    void sayHello() {
        printf("Hello World!\n");


works fine when put into helloworld.h and called by main.cpp.

However, when it's put directly into main.cpp... it throws the (linker) error.

It seems all Qt objects must be put into their own H/CPP pair. At least that's what it makes me think.

Reference: qt-interest mailing list archive - undefined reference to vtable...

No comments:

Post a Comment

Be the first to comment!