Results 1 to 13 of 13

Thread: subclassing/inheritance QObject problem

  1. #1
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default subclassing/inheritance QObject problem (now vtable)

    Hi all,
    I am having trouble integrating (by subclassing) an external C++ library into Qt. This library contains some unix sockets classes, which of course contains the connect(.....) function.
    Of course this clashes with QObject when I try to subclass it. I get the following error:

    no matching function for call to 'Server::connect(int&, sockaddr*, unsigned int)' .....
    candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*)
    Is there any way I can fix this without rewriting the external library to use Qt's network functions? (I really don't want to do this because this external library is being maintained independently and I want to make as few changes to it as possible).

    Thanks!
    Last edited by cbeall1; 13th February 2006 at 04:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Try adding "::" before that connect.

  3. #3
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: subclassing/inheritance QObject problem

    great. that took care of my error.
    Although now I get:
    undefined reference to 'vtable for Server'

    Server is the name of the class. I suspect I'm missing some include files, but the only one I see on http://doc.trolltech.com/3.3/signalsandslots.html that appears to be relevant is qframe.h, am I missing anything else?

    Also, I found the posts on the forum about including a .moc file. Although, I can't find one being generated anywhere. (I'm assuming it would show up in the .moc directory?)

    Here's my header file that causes the problem:

    Qt Code:
    1. #ifndef MYSOCKETS_H
    2. #define MYSOCKETS_H
    3.  
    4. #include "rbTree.h"
    5. #include "Fields.h"
    6.  
    7. // just for file testing
    8. #include <iostream>
    9. #include <fstream>
    10.  
    11. #include <qframe.h>
    12. //#include <qwidget.h>
    13. //#include <qapplication.h>
    14. #include <qobject.h>
    15.  
    16. using namespace std;
    17.  
    18. // global methods
    19. void* server_thread_stub(void*);
    20. void* server_rcv_thread_stub(void*);
    21. void* client_rcv_thread_stub(void*);
    22.  
    23. typedef struct position{
    24. int lateral;
    25. int distance;
    26. int vertical;
    27. };
    28.  
    29. typedef struct client_info{
    30. int fd;
    31. bool master;
    32. char ip[20];
    33. char name[100];
    34. int video;
    35. };
    36.  
    37. class Server: public QObject{
    38. //class Server{
    39. Q_OBJECT
    40.  
    41. public:
    42. Server(int);
    43. ~Server();
    44. int server_thread(void);
    45. int getImage();
    46. // client functions
    47. int connectClient(int);
    48. int send();
    49. int sendImage(char *);
    50. friend int receive_message(int);
    51. friend void* server_rcv_thread_stub(void*);
    52. friend void* client_rcv_thread_stub(void*);
    53. rbTree<int> client_tree;
    54.  
    55. //Server( QObject *parent=0, const char *name=0 );
    56.  
    57. private:
    58. static unsigned long int tid;
    59. int port;
    60. int newsockfd;
    61. int newClientsockfd;
    62.  
    63. };
    64.  
    65. #endif //MYSOCKETS_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by cbeall1; 13th February 2006 at 05:14. Reason: Clarification of problem

  4. #4
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Could you post your .pro file? I have the feeling that something is missing there

  5. #5
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: subclassing/inheritance QObject problem

    Here it is: (Everything compiles and runs fine when I take out the QOBJECT macro above.)
    And thanks for looking at this!

    Qt Code:
    1. TEMPLATE = app
    2. LANGUAGE = C++
    3.  
    4. CONFIG += qt warn_on release
    5.  
    6. INCLUDEPATH += ../bvz/
    7.  
    8. SOURCES += main.cpp \
    9. ../my_sockets/my_sockets.cpp \
    10. ../bvz/jval.cpp
    11.  
    12. FORMS = mainform.ui
    13.  
    14. IMAGES = images/filenew \
    15. images/fileopen \
    16. images/filesave \
    17. images/print \
    18. images/undo \
    19. images/redo \
    20. images/editcut \
    21. images/editcopy \
    22. images/editpaste \
    23. images/searchfind
    24.  
    25. unix {
    26. UI_DIR = .ui
    27. MOC_DIR = .moc
    28. OBJECTS_DIR = .obj
    29. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by cbeall1; 13th February 2006 at 13:15.

  6. #6
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: subclassing/inheritance QObject problem, complete error

    I suppose it would help to post the detailed error on compile. I've also included some warnings that happen just before the error, but I think those have nothing to do with my problem:

    g++ -c -pipe -Wall -W -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -mt une=pentium4 -fasynchronous-unwind-tables -DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/ usr/lib/qt-3.3/mkspecs/default -I. -I../bvz -I/usr/lib/qt-3.3/include -I.ui/ -I. -I.moc/ -o .obj/moc_mainform.o .moc/moc_mainform.cpp
    /usr/lib/qt-3.3/include/private/qucom_p.h:69: warning: ‘struct QUBuffer’ has virtual functio ns but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:77: warning: ‘struct QUType’ has virtual functions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:104: warning: ‘struct QUType_Null’ has virtual fun ctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:287: warning: ‘struct QUType_enum’ has virtual fun ctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:307: warning: ‘struct QUType_ptr’ has virtual func tions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:326: warning: ‘struct QUType_iface’ has virtual fu nctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:345: warning: ‘struct QUType_idisp’ has virtual fu nctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:364: warning: ‘struct QUType_bool’ has virtual fun ctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:383: warning: ‘struct QUType_int’ has virtual func tions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:403: warning: ‘struct QUType_double’ has virtual f unctions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:423: warning: ‘struct QUType_charstar’ has virtual functions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucom_p.h:444: warning: ‘struct QUType_QString’ has virtual functions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucomextra_p.h:65: warning: ‘struct QUType_QVariant’ has vir tual functions but non-virtual destructor
    /usr/lib/qt-3.3/include/private/qucomextra_p.h:87: warning: ‘struct QUType_varptr’ has virtu al functions but non-virtual destructor
    g++ -o server_gui .obj/main.o .obj/my_sockets.o .obj/jval.o .obj/mainform.o .obj/qmake_imag e_collection.o .obj/moc_mainform.o -L/usr/lib/qt-3.3/lib -L/usr/X11R6/lib -lqt-mt -lXext - lX11 -lm
    .obj/my_sockets.o(.text+0x1e5): In function `Server::~Server()':
    ../my_sockets/my_sockets.cpp:31: undefined reference to `vtable for Server'
    .obj/my_sockets.o(.text+0x229): In function `Server::~Server()':
    ../my_sockets/my_sockets.cpp:31: undefined reference to `vtable for Server'
    .obj/my_sockets.o(.text+0x265): In function `Server::~Server()':
    ../my_sockets/my_sockets.cpp:31: undefined reference to `vtable for Server'
    .obj/my_sockets.o(.text+0x31a): In function `Server::Server(int)':
    ../my_sockets/my_sockets.cpp:20: undefined reference to `vtable for Server'
    .obj/my_sockets.o(.text+0x3cc): In function `Server::Server(int)':
    ../my_sockets/my_sockets.cpp:20: undefined reference to `vtable for Server'
    collect2: ld returned 1 exit status
    make: *** [server_gui] Error 1

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Try running "qmake && make".

  8. #8
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: subclassing/inheritance QObject problem

    oh yes, I've done that many times hoping I just needed a new Makefile, but no luck.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Aren't you missing the HEADERS variable from your .pro file?

  10. #10
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: subclassing/inheritance QObject problem

    Hmm. Everything works fine when I take out the Qobject subclass and macro, with the .pro file as it is. Is a HEADERS variable something additional that's needed when I create my own subclass with QOBJECT?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Quote Originally Posted by cbeall1
    Is a HEADERS variable something additional that's needed when I create my own subclass with QOBJECT?
    qmake scans header files for Q_OBJECT macro and when it finds one it adds a rule to the Makefile that such file should be processed with moc program. In other words, if you don't put your headers in HEADERS variable, moc won't be run and you will get "undefined reference to vtable" errors.

  12. #12
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: subclassing/inheritance QObject problem

    AWESOME! Problem solved. Thanks jacek!
    I still get the warnings on /qucom_p as shown above. Are those something I need to be concerned about that could cause me trouble in the future?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing/inheritance QObject problem

    Quote Originally Posted by cbeall1
    I still get the warnings on /qucom_p as shown above. Are those something I need to be concerned about that could cause me trouble in the future?
    http://www.qtcentre.org/forum/showthread.php?t=266

Similar Threads

  1. Possibly an inheritance problem with QObject?
    By chadkeck in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2008, 01:26
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Problem with my object hierarchy
    By rage in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 09:18
  4. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07
  5. Problem with Destructor of QObject
    By mikro in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2006, 19:05

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.