[PyQt] [SIP] is there a Qt5 example for SIP?

Mathias.Born at gmx.de Mathias.Born at gmx.de
Sun Jul 7 19:22:11 BST 2013


On 07.07.2013, 13:46:02 brett at stottlemyer.com wrote:
>> On Sat, 6 Jul 2013 07:30:43 -0700, brett at stottlemyer.com wrote:
>>> Hi Phil,
>>>
>>> I am trying to see if SIP will help me with a task I'm trying to solve.
>> I
>>> started out by trying the More Complex C++ Example in the docs.
>> However,
>>> I'm using Qt5, and the example is for Qt4.
>>>
>>> I see the pyqtconfig is part of Qt4, but not Qt5.  No problem, except
>>> pyqtconfig is pretty integrated into the example, and as a beginner, I'm
>>> not sure how to take pyqtconfig out.
>>>
>>> Is there a Qt5 example for SIP?
>>
>> Look at the configure.py for PyQt5. A minimal build system would just be a
>> shell script that invoked sip then the C++ compiler then the linker. The
>> only thing you need to consider is to use the right -t flags to sip and
>> these can be found by introspecting current versions of PyQt.
>>
>> Phil
>>

> Thanks for the pointers.  I've got the example working.  But now I'm
> having trouble extending the example.

> I've got a bunch of enums I need to make available, some of which have
> overlapping names.  I've been handling this by putting them in different
> namespaces.  But sip is complaining about that.  I saw an old mailing list
> question on the topic
> (http://www.riverbankcomputing.com/pipermail/pyqt/2007-August/016847.html),
> but no solution was posted.

> My .h file is:
> // Define the interface to the hello library.

> #include <qlabel.h>
> #include <qwidget.h>
> #include <qstring.h>

> #if defined HELLO_DLL
> #  define HELLO_DLLSPEC  Q_DECL_EXPORT
> #else
> #  define HELLO_DLLSPEC Q_DECL_IMPORT
> #endif

> namespace MyNamespace { enum MyEnum { No=0, Yes=1}; };

> class HELLO_DLLSPEC Hello : public QLabel {
>     // This is needed by the Qt Meta-Object Compiler.
>     Q_OBJECT

> public:
>     Hello(QWidget *parent = 0);

> private:
>     // Prevent instances from being copied.
>     Hello(const Hello &);
>     Hello &operator=(const Hello &);
> };

> #if !defined(Q_OS_WIN)
> void setDefault(const QString &def);
> #endif

> My .sip file is:
> // Define the SIP wrapper to the hello library.

> %Module hello

> %Import QtGui/QtGuimod.sip
> %Import QtWidgets/QtWidgetsmod.sip

> %If (Qt_5_0_0 -)

> namespace MyNamespace
> {
> %TypeHeaderCode
> #include <hello.h>
> %End
> enum MyEnum { No=0, Yes=1};
> };

> class Hello : public QLabel {

> %TypeHeaderCode
> #include <hello.h>
> %End

> public:
>     Hello(QWidget *parent /TransferThis/ = 0);

> private:
>     Hello(const Hello &);
> };

> %If (!WS_WIN)
> void setDefault(const QString &def);
> %End

> %End

> The compiler (linker, actually) is complaining about missing symbols:
>    Creating library release\hello.lib and object release\hello.exp
> siphellocmodule.obj : error LNK2001: unresolved external symbol "struct
> _pyqt4ClassTypeDef sipTypeDef_hello_MyNamespace"
> (?sipTypeDef_hello_MyNamespace@@3U_pyqt4ClassTypeDef@@A)
> release\hello.dll : fatal error LNK1120: 1 unresolved externals

> What's the proper way to describe this to sip?

Hi,

Are you really compiling and linking all C++ files generated by SIP?

Best Regards,
Mathias Born




More information about the PyQt mailing list