The Qt projects on QtCreator usually keep main.cpp separated from QtMainWindow derived classes.
I tried to move it to main.cpp but got stuck:
myapp.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
CONFIG += c++11
SOURCES += main.cpp
main.cpp
#include <QApplication>
#include <QMainWindow>
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent=0) : QMainWindow(parent) { }
virtual ~MainWindow() override {}
};
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
return a.exec();
}
Then and got:
Undefined symbols for architecture x86_64:
"vtable for MainWindow", referenced from:
_main in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [demo1.app/Contents/MacOS/demo1] Error 1
Having a difficult time trying to find the mistake I made. Any comments?