Question

I'm getting a weird error with my slots and signals code in Qt v4.8.5. Whenever I include my QObject with slots:

class dnEventHandler : public QObject
{
    Q_OBJECT
public slots:
    void LaunchProjectCreator();
};

I get some odd errors:

Main.cc:(.text.startup+0x4b): undefined reference to `vtable for dnEventHandler'
Main.cc:(.text.startup+0x19e): undefined reference to `vtable for dnEventHandler'
Main.cc:(.text.startup+0x20d): undefined reference to `vtable for dnEventHandler'

I thought this was pretty strange, since it seemed the error had something to do with headers in the .pro, but I already had my headers in an include path in the .pro like so:

INCLUDEPATH += ../../include/

Why am I getting undefined references like this with my headers in my include path?

No correct solution

OTHER TIPS

There are two solutions for this issue, but your concrete issue may boil down to the same root cause which is to put the header file in question into the HEADERS variable. Having done this, you may need to make sure to reissue the qmake command.

Based on your question, it is not clear that it will do the job on its own since we have not seen neither your build system, nor the source file, but:

1) Make the build system take care of the issue. This looks simpler at first.

2) Use #include "foo.moc" in the end of the source file to avoid it. This version will work with any build system in the same way once the moc file is generated.

Turns out you have to manually specify all your headers with slots in the .pro:

HEADERS += yourHeader.h

Qt has to use this to generate MOC (Meta Object Code) files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top