Results 1 to 5 of 5

Thread: Undefined reference to 'vtable for XXX'

  1. #1
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Undefined reference to 'vtable for XXX'

    I am using QT 4 to design GUI of my software.

    I have a Controller class derived from QObject (because I want to use signals-slots mechanism). But when I build the project, the moc_Controller.cpp redefined some of member function in Controller.cpp and cause the compile problem. I decided to remove moc_Controller.cpp in Makefile. Then it causes link error called "Undefined reference to 'vtable for Controller".

    Is that because there is some pure virtual function in QObject (I did not find it)?

    Any help is appreciated, thanks.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Undefined reference to 'vtable for XXX'

    If you use Q_OBJECT (i.e. declare signals, slots, properties, Q_ENUMs...) then you need the code compiled by moc. (The Q_OBJECT macro declares stuff the the moc-generated code defines.)

    HTH

  3. The following user says thank you to caduel for this useful post:

    Sheng (16th October 2008)

  4. #3
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to 'vtable for XXX'

    Quote Originally Posted by caduel View Post
    If you use Q_OBJECT (i.e. declare signals, slots, properties, Q_ENUMs...) then you need the code compiled by moc. (The Q_OBJECT macro declares stuff the the moc-generated code defines.)

    HTH
    I removed the re-definition in moc_Controller, now it works fine. I do not understand why moc_Controller want to redefine my function.

  5. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Undefined reference to 'vtable for XXX'

    moc_XXX does not redefine your functions, it implements your signals, among other things.

  6. #5
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to 'vtable for XXX'

    Quote Originally Posted by caduel View Post
    moc_XXX does not redefine your functions, it implements your signals, among other things.
    Thanks, so I guess I do not need to implement signals in my code.
    Last edited by Sheng; 17th October 2008 at 17:32.

Similar Threads

  1. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 18:33
  2. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 14:41
  3. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 15:28
  4. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 20:15
  5. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 20:36

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.