example needed: sip + Qt

U

Uwe Mayer

Hi,

can someone provide me with a running example for subclassing QWidget (or
something similarly simple) in C++ and then creating SIP (4.x+) bindings
for in for Python (2.3+)?

I am looking for something I can start of with and work my way towards more
complicated stuff (with Qt).

The QLabel example in the SIP reference manual yields syntax errors for me.
Same with:
http://www.pegasus.rutgers.edu/~elflord/unix/siptute/subclass_example.tgz

thanks,
Uwe
 
C

Craig Ringer

Hi,

can someone provide me with a running example for subclassing QWidget (or
something similarly simple) in C++ and then creating SIP (4.x+) bindings
for in for Python (2.3+)?

Out of curiosity, would this be for an extension module used in an
embedded Python interpreter, or for plain extension module for use with
a standalone interpreter?

I'm afraid I can't help you with your specific problem, though I'll be
interested to hear if anybody here does know.

If you don't have any luck here, try the PyQt/PyKDE list (and search its
archives first).
 
P

Phil Thompson

Hi,
can someone provide me with a running example for subclassing QWidget (or
something similarly simple) in C++ and then creating SIP (4.x+) bindings
for in for Python (2.3+)?

I am looking for something I can start of with and work my way towards
more
complicated stuff (with Qt).

The QLabel example in the SIP reference manual yields syntax errors for
me.

What syntax errors? If there is a documentation bug then I'll fix it.

Phil
 
U

Uwe Mayer

What syntax errors? If there is a documentation bug then I'll fix it.

I'll come to that a little later, that happened in the simple c++ word
example.

I am currently fiddling around with the QLabel example. I copied the example
and tried it out. First problem was that the generated makefile does not
attempt to compile the original hello.cpp sources.

So I wrote a configure script and a Makefile.am for that.
It was not clear to me what type of archive or object was needed, so I first
tried creating a normal object file, then libtool archives and then normal
archives. It turned out I needed a normal archive an the library search path
has to be extended to include the current directory (-L.), i.e. where the
libhello.a lies.
My only way of doing so was edditing the Makefile generated by configure.py.
Is there a way of telling that to configure.py?

So now the hello.cpp example compiles. I fire up python:Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: ./hello.so: undefined symbol: _ZTV5Hello

$ c++filt _ZTV5Hello
vtable for Hello

The compilation did not give any warnings or error messages. Any ideas?

Thanks
Uwe
--
It would seem that evil retreats when forcibly confronted.
-- Yarnek of Excalbia, "The Savage Curtain", stardate 5906.5

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iQEVAwUAQfq6JeU60gD77wDfAQJoiQf/UIH66LxzzrxqwUNEIOFruIuMmICoWvqZ
S/INqzmLaOzhcpoj/lN1i0YjroGT1AWR08LtIuew4JCQX0IQejgZ0nefzMDjgDs4
BLcL1Aofj6CQm5tVdEglZvCZ9XXE3VKuXgQJtU7xVuhW2JEHsMLuGREdgpphxGl0
I67HRD//+/m7F66a3/CEfurycvljjNenCkn3mCMKBHnXGNXX2TeE8dtYPVGPcN9n
8SmVsAOcR3g/SsgEJSSYxi2pZY47gn95AEqAZhB7XSJNBp/xbFEk5Ha1XInvfsBw
uuePMDwzhOPsZNauJxpnoYWKPg+gcGukqAFi4zoXRA6ZvU9xgO3gXg==
=FFcq
-----END PGP SIGNATURE-----
 
U

Uwe Mayer

Out of curiosity, would this be for an extension module used in an
embedded Python interpreter, or for plain extension module for use with
a standalone interpreter?

I am writing an application program using Python and PyQt:
https://savannah.nongnu.org/projects/lmc/

At one point I am using a QListView but need my items to be sorted
numerically. There is no function to set the sort-criterea and the solution
to this is subclassing QListViewItem and overwrite the comparison functions.
However, doing so in Python was awfully slow for a greater number of items,
so I want to rewrite this in C++ and wrap it back to python.

Ciao
Uwe
--
Kilroe hic erat!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iQEVAwUAQfq7GOU60gD77wDfAQJgtAf/QsZbbCuNO3vcrf8TOMv1Vcti7w/iMw/W
fBJkcIokbX6HrnU4oVWnHc8Zz1DAXsxMSNPp2bC65TfPNgGzepEJHX/LvHhvHTOR
BN38BmmXhZysCPj+hE8a0sXs/4mCOZVBfjJ9Wn5hRsymMSZ0/R+oc2KfPLZSM0Ga
eri+rokfW+e4JECM5YVOc9pXM6rWY7aNC+NEx1m05Z3t+28CHwH+Kfw+qQfNDXyI
va84m6kNe3alCSXgGwRK5q6639BjBjW36xjdfzxl+sCACcIBB6xeJZ5Hhgc61hWK
6N6ZIBomzM1QgC3sAUK24cjbh0BMpOJweBKD18tFG2prUKSb3tSyRA==
=55t6
-----END PGP SIGNATURE-----
 
U

Uwe Mayer

Friday said:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: ./hello.so: undefined symbol: _ZTV5Hello

$ c++filt _ZTV5Hello
vtable for Hello

The compilation did not give any warnings or error messages. Any ideas?

$ ldd -d hello.so
libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0x40057000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4190c000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4154e000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x41173000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40743000)
libm.so.6 => /lib/tls/libm.so.6 (0x4114f000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x407fd000)
libc.so.6 => /lib/tls/libc.so.6 (0x41019000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x418d8000)
libaudio.so.2 => /usr/lib/libaudio.so.2 (0x40807000)
libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4191c000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x4081c000)
libz.so.1 => /usr/lib/libz.so.1 (0x41856000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x41749000)
libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40842000)
libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x41734000)
libXft.so.2 => /usr/lib/libXft.so.2 (0x416e1000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x42487000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x42583000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x4256a000)
libdl.so.2 => /lib/tls/libdl.so.2 (0x41184000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x40847000)
undefined symbol: _ZTV5Hello (./hello.so)
undefined symbol: _ZNK5Hello9classNameEv (./hello.so)
undefined symbol: _ZN5Hello7qt_castEPKc (./hello.so)
undefined symbol: _ZN5Hello9qt_invokeEiP8QUObject (./hello.so)
undefined symbol: _ZN5Hello7qt_emitEiP8QUObject (./hello.so)
undefined symbol: _ZN5Hello11qt_propertyEiiP8QVariant (./hello.so)
undefined symbol: _ZTI5Hello (./hello.so)
undefined symbol: _Py_NoneStruct (./hello.so)
undefined symbol: PyCObject_Type (./hello.so)

Uwe
 
U

Uwe Mayer

Friday said:
$ ldd -d hello.so
libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0x40057000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4190c000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4154e000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x41173000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40743000)
libm.so.6 => /lib/tls/libm.so.6 (0x4114f000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x407fd000)
libc.so.6 => /lib/tls/libc.so.6 (0x41019000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x418d8000)
libaudio.so.2 => /usr/lib/libaudio.so.2 (0x40807000)
libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4191c000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x4081c000)
libz.so.1 => /usr/lib/libz.so.1 (0x41856000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x41749000)
libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40842000)
libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x41734000)
libXft.so.2 => /usr/lib/libXft.so.2 (0x416e1000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x42487000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x42583000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x4256a000)
libdl.so.2 => /lib/tls/libdl.so.2 (0x41184000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x40847000)
undefined symbol: _ZTV5Hello (./hello.so)
undefined symbol: _ZNK5Hello9classNameEv (./hello.so)
undefined symbol: _ZN5Hello7qt_castEPKc (./hello.so)
undefined symbol: _ZN5Hello9qt_invokeEiP8QUObject (./hello.so)
undefined symbol: _ZN5Hello7qt_emitEiP8QUObject (./hello.so)
undefined symbol: _ZN5Hello11qt_propertyEiiP8QVariant (./hello.so)
undefined symbol: _ZTI5Hello (./hello.so)
undefined symbol: _Py_NoneStruct (./hello.so)
undefined symbol: PyCObject_Type (./hello.so)

Those last two can be removed if you link against libpython2.3.so and by
appending -lpython2.3 to the libs in the Makefile.

Uwe
 
P

Phil Thompson

So have you created the library you are trying to wrap? The documentation is
describing how to wrap a library and describes a fictional library as the
basis for the example.

Phil
 
U

Uwe Mayer

Saturday said:
So have you created the library you are trying to wrap? The documentation
is describing how to wrap a library and describes a fictional library as
the basis for the example.

No, the extracts from before are from the code example of the fictional
library with no further implementation.

By now I also found the problem: the poor python programmer did not care to
create the makefile (for building hello.cpp and hello.h) with qmake and
thus there were no moc files and that stupid programmer (me) could not link
against them.

It compiles and loads in python now.
Thanks
Uwe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,219
Messages
2,571,125
Members
47,731
Latest member
PasqualePf

Latest Threads

Top