Results 1 to 7 of 7

Thread: vtable problems

  1. #1
    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 vtable problems

    Hi,

    Due to various reasons, I have 2 class definitions in one header file, and their implementation in one implementation file.
    One is a Qt3 derived class, the other is not (all though it uses a Qt objects).
    The non Qt class is an implementation of an abstract class.
    When linking I got the "no reference to vtabele" for the non Qt class.
    The error is obvious - no vtable is generated for the non Qt class.
    To make sure, I put the implementation of that class in an implementation file of its own, and then it linked ok.
    All though the error is obvious, the reason for it is not (to me).
    So here are my questions:
    1. Is there any known issue with Qt that will not allow two vtables of two classes in one object file, or is this a general thing, not only with Qt?
    2. Did any of you managed to have such a setup as mine (more then one class in the same files (and with Qt)) and managed to have the vtable generated for all classes in the same object file, if so, would be nice if you could share how.

    Thanks in advance.
    ==========================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.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vtable problems

    This works fine:
    Qt Code:
    1. #ifndef ABSTRACT_H
    2. #define ABSTRACT_H
    3.  
    4. class QObject;
    5.  
    6. class abstract_class {
    7. public:
    8. abstract_class(){}
    9. ~abstract_class(){}
    10. protected:
    11. virtual void abstr_func1() = 0;
    12. virtual void abstr_func2(QObject*) = 0;
    13. };
    14.  
    15. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef XXXX_H
    2. #define XXXX_H
    3.  
    4. #include "abstract.h"
    5.  
    6. #include <QWidget>
    7.  
    8. class QObject;
    9.  
    10. class xxx : public QWidget {
    11. Q_OBJECT
    12. public:
    13. xxx(QWidget* parent);
    14. ~xxx();
    15. };
    16.  
    17. class nonqt : public abstract_class{
    18. public:
    19. nonqt(QObject* someptr);
    20. ~nonqt();
    21.  
    22. private:
    23. QWidget *w1;
    24. xxx* w2;
    25.  
    26. protected:
    27. void abstr_func1();
    28. void abstr_func2(QObject*);
    29. };
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 
    Are you sure you don't have any errors of your own?
    Can you post some code?

    Regards

  3. #3
    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: vtable problems

    This works fine
    Yes, but only if the implementation of 'xxx' and 'nonqt' are in separate cpp files.
    Does it work for you also when both classes are implemented in the same cpp file?

    No, I am not sure I don't have an error on my part, which is why I am asking...
    I don't know what code I should post, the code you posted illustrates my code quite well, only the problem is not in the header file, but in the implementation.
    As I said, when I separate the implementations, there are no problems.
    If you tell me which parts of the code might be interesting to look at, I'll post them.

    Thanks!
    ==========================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.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vtable problems

    As you can see, both classes are in the same header.

    Maybe you can post the class declarations. Hard to say where the problem might be.

    Regards

  5. #5
    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: vtable problems

    As you can see, both classes are in the same header.
    I am not sure I understand you...
    My problems is not with the declerations, or the header.
    My problems is, that if I put both *implementations* in the same cpp file, I get "undefined reference to vtabe" errors.
    If I put both implementations in two separates cpp files, all is well.
    Which suggests (to me) that the compiler for some reason, doesnt put the vatables of my abstract class in the objec file if this object file shares two classes, and I was wondering if the this is a known issue, and if/what can be done to allow the implementation of both classes in the same file.

    Thanks.
    ==========================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.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vtable problems

    I never had these kind of problems. Perhaps my example has something small but significantly different than yours.

    Also, my implementation of the classes are in the same cpp.

    I compiled mine only with VS 2005. What compiler do you use?

    Maybe you can create a small example that reproduces your problem.

    Regards

  7. #7
    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: vtable problems

    thanks for your help.
    I think my problem has more to do with the overall project structure and make file calling order.
    I'll have a look in that direction and make sure that all is correct in that regard.
    If it still doesn't work then I'll ask again with more details.

    thanks again.
    ==========================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.

Similar Threads

  1. Replies: 2
    Last Post: 8th March 2007, 22:22
  2. Problems with Unicode(UTF8)
    By cristiano in forum Qt Programming
    Replies: 15
    Last Post: 5th December 2006, 12:33
  3. Utf8 problems
    By cristiano in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2006, 00:14
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.