[Qt-interest] Inheritance limitations

Scott Sibley sisibley at gmail.com
Tue Oct 13 01:02:04 CEST 2009


Probably true. I just thought of a solution to my issue though. You see, I
needed a QObject slot, but a different method for each different class
deriving A. So the following might do it.

class A: public QObject { // The reason A needs to be a QObject is I have
some properties for QScript to access.
    Q_OBJECT

    public slots:
    void aMethod();
};

class B: public A {
    public:
    void aMethod(); // Class C would provide its own aMethod as well.
}

Of course I haven't tested this yet. I don't see why it wouldn't work.

On Mon, Oct 12, 2009 at 5:01 PM, Jason H <scorp1us at yahoo.com> wrote:

> If A inherits QObject, why inherit it again?
>
> class B: public A {
>     Q_OBJECT
> };
>
> Is all you should need. Right?
>
>
> ------------------------------
> *From:* Scott Sibley <sisibley at gmail.com>
> *To:* qt-interest at trolltech.com
> *Sent:* Mon, October 12, 2009 5:31:46 PM
> *Subject:* [Qt-interest] Inheritance limitations
>
> I get the following warning with these two classes. I think I'm learning to
> cope with it (I'm rewriting a pygtk app in C++ and QT, where I just dropped
> signals wherever I liked), but was curious why there's the limitation.
>
> [starlon at localhost tmp]$ moc-qt4 -I/usr/include/QtCore -o moc_test.cctest.h
> test.h:11: Warning: Class B inherits from two QObject subclasses QObject
> and A. This is not supported!
>
> // test.h
> class A: public virtual QObject {
>     Q_OBJECT
> };
>
> class B: public virtual QObject, public A {
>     Q_OBJECT
> };
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091012/73ea380e/attachment.html 


More information about the Qt-interest-old mailing list