Results 1 to 4 of 4

Thread: QObject inheriting class - problems with vtable and moc generation

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QObject inheriting class - problems with vtable and moc generation

    Despite all my attempts, and reading over many forum posts, I'm still getting the infamous 'undefined reference to 'vtable for GameStructure'' error.

    I've had this error before, and resolved it multiple times in the past, but this time I can't figure it out. Despite calling qmake, moc_GameStructure.cpp is not getting generated.

    Here's my code:

    Qt Code:
    1. #ifndef GAMESTRUCTURE_H
    2. #define GAMESTRUCTURE_H
    3.  
    4. #include <QObject>
    5.  
    6. class GameStructure : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit GameStructure(QObject *parent = 0);
    11.  
    12. signals:
    13.  
    14. public slots:
    15. void testSlot();
    16. };
    17.  
    18. #endif // GAMESTRUCTURE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "GameStructure.h"
    2.  
    3. GameStructure::GameStructure(QObject *parent) :
    4. QObject(parent)
    5. {
    6.  
    7. }
    8.  
    9.  
    10. void GameStructure::testSlot()
    11. {
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    qmake does not generate the moc file for GameStructure, even though it does for another class in the same project. I've 'Rebuilt All', and 'Clean All' three hundred and seventy one times and counting.

    The exact error message is: "undefined reference to 'vtable for GameStructure'", which appears twice, followed by: "collect2: ld returned 1 exit status"

    Am I missing some pure virtual function that QObject declares that I must define when inheritting QObject directly? I just care about the signal-and-slot features about QObject, none of the rest of it matters to me for this class.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QObject inheriting class - problems with vtable and moc generation

    Make sure your source files are properly assigned to the correct HEADER and SOURCES variables in your .pro file.

  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QObject inheriting class - problems with vtable and moc generation

    Oh, wow. Missed that.

    But now I'm getting the, "Warning: No relevant classes found. No output generated." warning.
    The moc file is now created, but empty.

    The class does inherit from QObject ("class GameStructure : public QObject"), QObject is included (#include <QObject>),
    it does use the Q_OBJECT macro as the first line of the class definition, and it does have a slot as part of the definition.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QObject inheriting class - problems with vtable and moc generation

    Is the code you posted the EXACT code you have?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 13th May 2011, 00:43
  2. QOBJECT and undefined reference to vtable errors
    By stargazer in forum Qt Programming
    Replies: 7
    Last Post: 25th April 2011, 05:29
  3. Replies: 1
    Last Post: 7th March 2011, 14:02
  4. Inheriting from QwtPlotCurve problems
    By dbrmik in forum Qwt
    Replies: 5
    Last Post: 1st April 2009, 14:02
  5. QListWidget inheriting custom class
    By phannent in forum Qt Tools
    Replies: 1
    Last Post: 4th August 2008, 14:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.