469,299 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

example needed: sip + Qt

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/~elfl...ss_example.tgz

thanks,
Uwe
Jul 18 '05 #1
8 2701
On Fri, 2005-01-28 at 13:30 +0100, Uwe Mayer wrote:
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).

--
Craig Ringer

Jul 18 '05 #2
> 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

Jul 18 '05 #3
On Friday 28 January 2005 14:47 pm, Phil Thompson wrote:
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.


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:
import hello

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
BLcL1Aofj6CQm5tVdEglZvCZ9XXE3VKuXgQJtU7xVuhW2JEHsM LuGREdgpphxGl0
I67HRD//+/m7F66a3/CEfurycvljjNenCkn3mCMKBHnXGNXX2TeE8dtYPVGPcN9n
8SmVsAOcR3g/SsgEJSSYxi2pZY47gn95AEqAZhB7XSJNBp/xbFEk5Ha1XInvfsBw
uuePMDwzhOPsZNauJxpnoYWKPg+gcGukqAFi4zoXRA6ZvU9xgO 3gXg==
=FFcq
-----END PGP SIGNATURE-----

Jul 18 '05 #4
On Friday 28 January 2005 14:24 pm, Craig Ringer wrote:
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
fBJkcIokbX6HrnU4oVWnHc8Zz1DAXsxMSNPp2bC65TfPNgGzep EJHX/LvHhvHTOR
BN38BmmXhZysCPj+hE8a0sXs/4mCOZVBfjJ9Wn5hRsymMSZ0/R+oc2KfPLZSM0Ga
eri+rokfW+e4JECM5YVOc9pXM6rWY7aNC+NEx1m05Z3t+28CHw H+Kfw+qQfNDXyI
va84m6kNe3alCSXgGwRK5q6639BjBjW36xjdfzxl+sCACcIBB6 xeJZ5Hhgc61hWK
6N6ZIBomzM1QgC3sAUK24cjbh0BMpOJweBKD18tFG2prUKSb3t SyRA==
=55t6
-----END PGP SIGNATURE-----

Jul 18 '05 #5
Friday 28 January 2005 23:18 pm Uwe Mayer wrote:
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
Jul 18 '05 #6
Friday 28 January 2005 23:39 pm Uwe Mayer wrote:
Friday 28 January 2005 23:18 pm Uwe Mayer wrote:
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)


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
Jul 18 '05 #7
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

On Friday 28 January 2005 11:02 pm, Uwe Mayer wrote:
Friday 28 January 2005 23:39 pm Uwe Mayer wrote:
Friday 28 January 2005 23:18 pm Uwe Mayer wrote:
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)


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

Jul 18 '05 #8
Saturday 29 January 2005 00:23 am Phil Thompson wrote:
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
Jul 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ville Vainio | last post: by
12 posts views Thread by Xah Lee | last post: by
20 posts views Thread by Xah Lee | last post: by
10 posts views Thread by Bart Goeman | last post: by
13 posts views Thread by KV | last post: by
12 posts views Thread by emma_middlebrook | last post: by
25 posts views Thread by meltedown | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.