[Qt-interest] moc / multiple inheritance issue
Jimmy Cooksey
jcooksey at gmail.com
Mon Sep 14 02:21:52 CEST 2009
Hello Everyone,
I'm experiencing a strange problem where moc appears to be hijacking a
method call to my object that is multiply inheriting from some widget
and another base class.
Here is some sample code:
// This is the base class
class DeclareYourself
{
public:
DeclareYourself() { };
virtual ~DeclareYourself() { };
virtual void declareYourself() = 0;
};
class SpecialLineEdit : public QLineEdit, public DeclareYourself
{
Q_OBJECT
public:
SpecialLineEdit(QWidget* parent) : QLineEdit(parent), DeclareYourself();
~SpecialLineEdit() { }
void declareYourself()
{
setText("I'm a line edit!");
return;
}
};
So when I create this object, I'm using something like...
QWidget* specialLineEdit = new SpecialLineEdit(this);
The interesting thing is that this call...
((*DeclareYourself) specialLineEdit)->declareYourself();
... never calls SpecialLineEdit::declareYourself()
It immediately calls this:
SpecialLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
and of course, I have no idea why.
The code itself compiles just fine, and the application does not crash.
I have created a sample project demonstrating my problem:
http://www.jimster.org/QtTestCase.zip
Any help would be greatly appreciated!
Thanks,
Jimmy
More information about the Qt-interest-old
mailing list