[PyKDE] provide custom widget to python

Phil Thompson phil at riverbankcomputing.co.uk
Mon Dec 15 23:14:00 GMT 2003


On Monday 15 December 2003 10:03 pm, Jan Drugowitsch wrote:
> On Monday 15 December 2003 17:02, Jim Bublitz wrote:
> > On Monday December 15 2003 08:13, Jan Drugowitsch wrote:
> > > Hi everyone,
>
> [snip]
>
> > > My .sip file declares the TokenDisplay class by inheriting
> > > QScollView. How do I get the reference to QScollView in there
> > > without including the whole qtmod.sip?
> > > That's the beginning of my .sip class declaration:
> > >
> > > class TokenDisplay : QScrollView
> > > {
> > > %HeaderCode
> > > #include "tokendisplay.h"
> > > %End
> > >
> > > public:
> > >     // enumeration for TokenClicked signal
> > >     enum MouseButton { RightButton, LeftButton };
> > >
> > >     TokenDisplay(QWidget* /TransferThis/ = 0, const char* =
> > > 0); [snip]
> > >
> > > Without including anything I get
> > > sip: QScrollView has not been defined
> > > If I include qtmod.sip, headers and wrappers for all the qt
> > > classes get generated and that's not what I want.
> > >
> > > Although I've searched through the mailing list I'm not much
> > > wiser than before. Does anyone have any cues I can start with?
> > > Sorry if this question's already been asked several times
> > > before.
>
> [snip]
>
> > Second, somewhere you need to add:
> >
> >     %Import qtmod.sip
> >
> > For PyQt and PyKDE there is normally a "top-level" sip file which
> > controls sip's code generation and is the file name you pass
> > when you invoke 'sip' to generate C++ code. It should look
> > something like:
> >
> > %Module tokendisplay
> >
> > %Import qtmod.sip
> >
> > %Include tokendisplay.sip
> >
> > The "top-level" sip file needs to be named  something other than
> > "tokendisplay.sip" if that's the name of the sip file that
> > contains the class definition. Look at PyQt (eg  qtmod.sip) or
> > PyKDE (eg dcop-kde*.sip, kdecore-kde*.sip) for examples of
> > "top-level" sip files. You'll also need to provide a path to the
> > PyQt sip files and link to libqtcmodule.so (-L <site-packages
> > path> -l qtcmodule) as well as libqt-mt.so.
> >
> > The %Import will cause the generation of a lot of C++ h files by
> > sip, but won't generate any cpp files by itself (as %Include
> > would).
>
> Thanks, both of you, %Import was what I was searching for. After some minor
> modifications I was able to get sip run error-free. Compilation and linking
> also worked, but it seems I am missing a library somewhere. The commands I
> am using:
>
> sip -I /usr/share/sip/qt -t Qt_3_2_0 -t WS_X11 -c td_sip tokendisplay.sip
> g++ -c -Wall -o libTokenDisplayc.o -I /usr/include/python2.2 -I /usr/qt/3/
> include -I td_sip -I . td_sip/TokenDisplaycmodule.cpp
> g++ -shared -o libTokenDisplayc.so -L /usr/lib/python2.2/site-packages -l
> qtcmodule -L /usr/qt/3/lib -l qt-mt libTokenDisplayc.o
>
> When i try to import the module in python i get the following:
> >>> import TokenDisplay
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "TokenDisplay.py", line 8, in ?
>     import libTokenDisplayc
> ImportError: ./libTokenDisplayc.so: undefined symbol:
> _ZTV20sipProxyTokenDisplay
>
> nm libTokenDisplayc.so | grep sipProxyTokenDisplay gives
> 000014b4 T _ZN20sipProxyTokenDisplay12getProxySlotEPc
> 000014d6 T
> _ZN20sipProxyTokenDisplay9proxySlotEN12TokenDisplay11MouseButtonEj 000015ea
> T _ZN20sipProxyTokenDisplay9proxySlotEP7QObject
> 00001560 T _ZN20sipProxyTokenDisplay9proxySlotEii
> 00001684 T _ZN20sipProxyTokenDisplay9proxySlotEv
> 000018e2 W _ZN20sipProxyTokenDisplayC1Ev
>          U _ZTV20sipProxyTokenDisplay
> 00002d7c d _ZZN20sipProxyTokenDisplay12getProxySlotEPcE3tab
>
> Neither libqtcmodule.so nor libsip.so contain this symbol either.
> Any clue what's wrong here?

There will be a .h file that was generated (sorry, can't remember the name at 
the moment as it varies between some SIP versions) that you need to run moc 
on and compile and link the C++ code it generates.

Phil




More information about the PyQt mailing list