Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `vtable for MainWindow'

Tags:

c++

eclipse

qt

I'm following Qt's guide for using a QPushButton.

I did exactly as the guide suggests, but I'm getting a compilation error:

./src/mainwindow.o: In function `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:(.text+0x1d): undefined reference to `vtable for MainWindow'
./src/mainwindow.o:mainwindow.cpp:(.text+0x25): more undefined references to `vtable for MainWindow' follow
collect2: error: ld returned 1 exit status
make: *** [HelloWorldProj] Error 1

I tried adding a destructor:

~MainWindow(){};

but the problem persisted.

I have no virtual functions declared, except one function inside QMainWindow (the class I'm inheriting from):

virtual QMenu *createPopupMenu();

Should this be defined in my class?

like image 339
Alaa M. Avatar asked Nov 10 '15 15:11

Alaa M.


1 Answers

You need to set CMAKE_AUTOMOC to ON in our CMake file.

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

"The AUTOMOC target property controls whether cmake inspects the C++ files in the target to determine if they require moc to be run, and to create rules to execute moc at the appropriate time." - Reference

like image 97
Dumisani Kunene Avatar answered Sep 30 '22 19:09

Dumisani Kunene