[Qt-interest] moc / multiple inheritance issue
Girish Ramakrishnan
girish at forwardbias.in
Mon Sep 14 07:14:32 CEST 2009
Haven't tried the code but I don't think this has anything to do with
moc. c-style casting + multiple inheritance is the issue. You should do
something like
(dynamic_cast<DeclareYourself *> specialLineEdit)->declareYourself();
Girish
Jimmy Cooksey wrote:
> 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