PDA

View Full Version : subclassing/inheritance QObject problem



cbeall1
13th February 2006, 01:26
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!

jacek
13th February 2006, 01:58
Try adding "::" before that connect.

cbeall1
13th February 2006, 02:32
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:


#ifndef MYSOCKETS_H
#define MYSOCKETS_H

#include "rbTree.h"
#include "Fields.h"

// just for file testing
#include <iostream>
#include <fstream>

#include <qframe.h>
//#include <qwidget.h>
//#include <qapplication.h>
#include <qobject.h>

using namespace std;

// global methods
void* server_thread_stub(void*);
void* server_rcv_thread_stub(void*);
void* client_rcv_thread_stub(void*);

typedef struct position{
int lateral;
int distance;
int vertical;
};

typedef struct client_info{
int fd;
bool master;
char ip[20];
char name[100];
int video;
};

class Server: public QObject{
//class Server{
Q_OBJECT

public:
Server(int);
~Server();
int server_thread(void);
int getImage();
// client functions
int connectClient(int);
int send();
int sendImage(char *);
friend int receive_message(int);
friend void* server_rcv_thread_stub(void*);
friend void* client_rcv_thread_stub(void*);
rbTree<int> client_tree;

//Server( QObject *parent=0, const char *name=0 );

private:
static unsigned long int tid;
int port;
int newsockfd;
int newClientsockfd;

};

#endif //MYSOCKETS_H

yop
13th February 2006, 08:40
Could you post your .pro file? I have the feeling that something is missing there ;)

cbeall1
13th February 2006, 13:06
Here it is: (Everything compiles and runs fine when I take out the QOBJECT macro above.)
And thanks for looking at this!


TEMPLATE = app
LANGUAGE = C++

CONFIG += qt warn_on release

INCLUDEPATH += ../bvz/

SOURCES += main.cpp \
../my_sockets/my_sockets.cpp \
../bvz/jval.cpp

FORMS = mainform.ui

IMAGES = images/filenew \
images/fileopen \
images/filesave \
images/print \
images/undo \
images/redo \
images/editcut \
images/editcopy \
images/editpaste \
images/searchfind

unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
}

cbeall1
13th February 2006, 16:01
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

jacek
13th February 2006, 16:07
Try running "qmake && make".

cbeall1
13th February 2006, 16:17
oh yes, I've done that many times hoping I just needed a new Makefile, but no luck.

jacek
13th February 2006, 16:19
Aren't you missing the HEADERS variable from your .pro file?

cbeall1
13th February 2006, 16:26
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?

jacek
13th February 2006, 16:37
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.

cbeall1
13th February 2006, 16:46
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?

jacek
13th February 2006, 17:49
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