PDA

View Full Version : vtable problems



high_flyer
31st August 2007, 18:28
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.

marcel
31st August 2007, 18:42
This works fine:


#ifndef ABSTRACT_H
#define ABSTRACT_H

class QObject;

class abstract_class {
public:
abstract_class(){}
~abstract_class(){}
protected:
virtual void abstr_func1() = 0;
virtual void abstr_func2(QObject*) = 0;
};

#endif


#ifndef XXXX_H
#define XXXX_H

#include "abstract.h"

#include <QWidget>

class QObject;

class xxx : public QWidget {
Q_OBJECT
public:
xxx(QWidget* parent);
~xxx();
};

class nonqt : public abstract_class{
public:
nonqt(QObject* someptr);
~nonqt();

private:
QWidget *w1;
xxx* w2;

protected:
void abstr_func1();
void abstr_func2(QObject*);
};

#endif
Are you sure you don't have any errors of your own?
Can you post some code?

Regards

high_flyer
3rd September 2007, 09:18
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!

marcel
3rd September 2007, 09:23
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

high_flyer
3rd September 2007, 10:50
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.

marcel
3rd September 2007, 13:39
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

high_flyer
3rd September 2007, 13:52
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.