Yes, I am getting "undefined reference to `vtable for Window'"

  • Hello,

    So, I am getting the error when I do the build:
    $ clang++ -g -std=c++14 subc*.cpp -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -lQtCore -lQtGui

    $ tmp/subcl-f65a46.o: In function Window': undefined reference tovtable for Window'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I am on Linux, I am not using Qt Creator, I am not using qmake. That is because this GUI qt project will be added to a (very) large project with its own build system based on make files.

    This is the example straight out of the Qt For Beginners page.

    // subcl.h
    #ifndef SUBCL_H
    #define SUBCL_H
    #include <QWidget>
    class Window : public QWidget
      explicit Window(QWidget *parent = 0);
      virtual ~Window();
     public slots:
    // subcl.cpp
    #include "subcl.h"
    Window::Window(QWidget *parent) : QWidget(parent) {}
    Window::~Window(void) {}
    // subclmain.cpp
    #include <QApplication>
    #include "subcl.h"
    int main(int argc, char **argv)
     QApplication app (argc, argv);
     Window window;;
     return app.exec();

    I've done the googling.

    Can someone help me with this -- thank you!

  • Note, I added the virtual desctructor (did not help.)

  • After adding the Q_OBJECT macro you must run the header through moc, compile the generated source, and include it in the link stage.

    Normally qmake would do that for you.

Log in to reply