[PyKDE] Passing C++-created QWidgets to embedded Python
Robin Summerhill
robinsummerhill at cyantechnology.com
Tue Apr 16 10:01:14 BST 2002
I finally worked out what was going wrong here.
It's to do with the requirement to mark declarations with
__declspec(DLLEXPORT) or _declspec(DLLIMPORT)to get DLL linking working
properly with MSVC.
SIP_EXTERN is declared in sip.h and ends up as SIP_EXPORT or SIP_IMPORT
according to whether the preprocessor symbols SIP_MAKE_DLL or SIP_USE_DLL
are defined. Sip.exe uses this declaration to enable sip-generated headers
to be used both in building the dll (EXPORT) and the client of the dll
(IMPORT). However, the sip-generated headers that are included in the PyQT
distribution have been edited to change SIP_EXTERN to SIP_EXPORT, meaning
that these headers can only be used to build the libqtc dll, *not* consume
it.
There is no clean way around this with the present setup, because SIP_EXTERN
is used in the SIP headers too. You can't just change SIP_EXPORT back to
SIP_EXTERN because that prevents you from building libqtc.
As a temporary measure, I'm keeping two sets of the libqtc headers - one to
build libqtc (with SIP_EXORT) and one to include in the client (with
SIP_EXTERN and SIP_USE_DLL defined)
Having done this (and recompiling everything with -MD to solve my other
problems) I can now embed PyQT and it's just *fantastic*
Robin Summerhill
-----Original Message-----
From: Phil Thompson [mailto:phil at river-bank.demon.co.uk]
Sent: 13 April 2002 11:33
To: Robin Summerhill
Subject: Re: [PyKDE] Passing C++-created QWidgets to embedded Python
Robin Summerhill wrote:
>
> Hi,
>
> I'm embedding PyQT in a C++ application and am trying to extend the
> interpreter with my app's object model.
>
> I know I need to do something like the following to pass a C++-created
> widget to Python:
>
> #include <Python.h>
> #include <sip.h>
> #include <sipqtQWidget.h>
>
> static PyObject *py_getWidget(PyObject *self, PyObject *args)
> {
> PyObject* p = sipMapCppToSelf(reinterpret_cast<void*>(pWidget),
> sipClass_QWidget);
> return p;
> }
>
> However, when I try to link this (MSVC6 with SP5) I get:
>
> error LNK2001: unresolved external symbol "struct _object *
> sipClass_QWidget" (?sipClass_QWidget@@3PAU_object@@A)
>
> I'm linking against libsip.lib and libqtc.lib. Looking at the exports from
> libqtc.lib with dumpbin, sipClass_QWidget is present and correct with the
> right mangled name. Other symbols such as sipQWidget *are* accessible.
>
> I'm probably doing something really stupid but I can't see it. Can anyone
> give me any insight or send my some example code that works?
It should work - but I'm not aware of anybody who has already done what
you are trying to do under Windows, and I am no Windows expert.
Phil
More information about the PyQt
mailing list