Results 1 to 3 of 3

Thread: Multiple reasons for vtable and linkage issues

  1. #1
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple reasons for vtable and linkage issues

    I spent much time today solving vtable issues, and similar linkage issues. I thought that I would share my findings.

    I have a class derived from QObject. I added the Q_OBJECT macro, and suddenly I had vtable issues with the class. All you QT veterans are smiling and nodding, because you know that I needed to run qmake to regenerate the make the file.

    1. Check link statements
    2. Verify that the method does indeed exist.
    3. Run qmake to regenerate the MAKEFILE
    4. Only use the Q_OBJECT macro in a header file.



    My next issue was subtle. My opinion is that this is probably a compiler error, but, I have not pursued it. This is a bit convoluted:
    1. My program uses library A
    2. Library A uses Library B
    3. While linking, some classes defined in Library B and used in Library A are not available (link issues).


    I have not pursued this entirely, but, I solved the problem by instantiating a class instance in my program. Defining an instance in library B did not help.

    I was very surprised by this.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multiple reasons for vtable and linkage issues

    While linking, some classes defined in Library B and used in Library A are not available (link issues).
    You have to link against both libs from your application, unless lib B is statically linked to A.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple reasons for vtable and linkage issues

    I do link to both libraries. The interesting problem is that if I do not instantiate an instance of a class in my main program, but only in library A, then certain things in B are not found. If I did not link both libraries, then creating an instance in the main program would not resolve the link error.

Similar Threads

  1. Replies: 17
    Last Post: 26th January 2010, 20:21
  2. compilation issues: multiple includes?
    By sfabel in forum Qt Programming
    Replies: 5
    Last Post: 23rd December 2009, 11:29
  3. Conditional linkage
    By TorAn in forum General Programming
    Replies: 1
    Last Post: 22nd December 2009, 21:10
  4. Replies: 1
    Last Post: 14th April 2007, 13:42
  5. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

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
  •  
Qt is a trademark of The Qt Company.