Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Minimal QObject example doesn't compile !
Forum Updated to NodeBB v4.3 + New Features

Minimal QObject example doesn't compile !

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 227 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • idlefrogI Offline
    idlefrogI Offline
    idlefrog
    wrote on last edited by idlefrog
    #1

    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"
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You forgot to add the header to HEADERS

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • idlefrogI Offline
        idlefrogI Offline
        idlefrog
        wrote on last edited by
        #3

        Yes...that's it. And I thought I was doing something wrong in the class somewhere!
        Many thanks!!!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved