0

I have the following program:

#include <QApplication>
#include <QMainWindow>

class Window : public QMainWindow
{
    Q_OBJECT
public:
    virtual ~Window() {};
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Window window;
    window.show();

    return app.exec();
}

I ran qmake to get a project file, but when I run make, I get:

main.cpp:(.text.startup+0x50): undefined reference to `vtable for Window'

Googling the problem I see a lot of solutions saying to add the header file for your class to the HEADERS variable in the qmake project file. But I don't have a header file. What can I do?

Jack M
  • 4,769
  • 6
  • 43
  • 67
  • The simplest way to fix this is to create a header for each of your Qt classes. – Mat May 27 '22 at 19:18
  • Looked at some answers to related questions and this one explains it thoroughly: https://stackoverflow.com/a/26928723/103167 – Ben Voigt May 27 '22 at 19:49
  • @BenVoigt That one's probably fine if you want to understand what's going on, but for fixing the immediate problem [this](https://stackoverflow.com/a/4774660/815612) was the only one that did it for me. – Jack M May 27 '22 at 19:58
  • @JackM: It seems like a bad idea to build software using a complicated system like Qt without understanding what's going on. I know, I know "all those details are supposed to be hidden from me". But that's a dangerous approach, much better to understand the complexity (which is still less work than designing and writing and maintaining the complexity, if you actually need the complexity) – Ben Voigt May 27 '22 at 20:27

0 Answers0