[PyQt] SIP gives error when trying to subclass QVariant

Phil Thompson phil at riverbankcomputing.com
Wed Apr 17 10:27:37 BST 2013


On Tue, 16 Apr 2013 11:53:37 -0700, Nate Reid <gnatty7 at hotmail.com> wrote:
> Versions: Redhat Linux EL6Qt 4.7.1 (also tested with 4.8.2)PyQt:
> 4.10Python: 2.7.4Sip: 4.14
> Sip 4.14, and 4.13 as well gives me the following error when trying to
> generate code on the following sip file:sip -x VendorID -t WS_X11 -x
> PyQt_NoPrintRangeBug -t Qt_4_7_1 -g -I /usr/pic1/root/share/sip/PyQt4 -c
.
> python/TestQVariant.sipsip: python/TestQVariant.sip:6: A class,
exception,
> namespace or mapped type has already been defined with the same name
> // TestQVariant.sip:%Module TestQVariant
> %Import QtCore/QtCoremod.sip
> class TestQVariant : public QVariant{%TypeHeaderCodeinclude
> "TestQVariant.h"$Endpublic:    TestQVariant(void);
>     TestQVariant(const QVariant &v);        TestQVariant(int v);       
>     TestQVariant(double v);       TestQVariant(const QString &v);
>     TestQVariant(const TestQVariant &a);
>     bool hasName(void) const;        const QString &name(void) const;   

>       void setName(const QString &name);
> };%End
> // TestQVariant.h#ifndef TestQVariant_h#define TestQVariant_h
> #include <QtCore/QVariant>#include <QtCore/QString>
> class TestQVariant : public QVariant{public:    TestQVariant(void)    { 

> }
>     TestQVariant(const QVariant &v) :        QVariant(v)    {    }      

>     TestQVariant(int v) :        QVariant(v)    {    }       
>     TestQVariant(double v) :        QVariant(v)    {    }       
>     TestQVariant(const QString &v) :        QVariant(v)    {    }
>     TestQVariant(const TestQVariant &a) :        QVariant(a),       
>     mName(a.mName)    {    }
>     TestQVariant &operator=(const TestQVariant &a)    {       
>     QVariant::operator=(a);        mName = a.mName;        return *this;
 
>     }        bool hasName(void) const    {        return
!mName.isEmpty(); 
>      }        const QString &name(void) const    {        return mName; 

>     }        void setName(const QString &name)    {        mName = name;
 
>     }    private:    QString mName;};
> #endif
> 
> Is this related to the API version that QVariant is using?

Yes.

> This is with
> Python 2.7, so it should default to '2'.

Actually '1'.

> Is there some other name I need
> to use for the QVariant class to get this to work?

No. Basically you can't sub-class from classes that have multiple
implementations (I've now documented this more clearly). This is a SIP bug
but not one that I'm going to rush to fix.

Have you got a real use case? (Given how Qt uses QVariant I can't see how
a sub-class can be useful.)

Phil


More information about the PyQt mailing list