Minimal QObject example doesn't compile !
Solved
General and Desktop
-
Why does this minimal example not compile?
I get the dreaded 'undefined reference to vtable' error. :(Header:
class MyObject: public QObject { Q_OBJECT public: MyObject(); virtual ~MyObject(); };
Definition:
MyObject::MyObject(){} MyObject::~MyObject(){}
My .pro file is:
QT += testlib QT += gui widgets CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle TEMPLATE = app SOURCES += \ MyObject.cpp \ tst_obj.cpp
I'm sure you don't need to have a slot/signal if you inherit from QObject. Is something very wrong with the .pro file?!
Although I don't think it's relevant, here's the test file:
#include <QtTest> #include "MyObject.h" class TestMyObject : public QObject { Q_OBJECT public: TestMyObject(); ~TestMyObject(); private slots: void test_createMyObject(); }; TestMyObject::TestMyObject(){} TestMyObject::~TestMyObject(){} void TestMyObject::test_createMyObject() { MyObject myObject; } QTEST_APPLESS_MAIN(TestMyObject) #include "tst_obj.moc"
-
You forgot to add the header to HEADERS