swig problem
Torsten Marek
torsten.marek at student.uni-tuebingen.de
Mon Feb 16 07:32:47 EST 2004
Uwe Mayer schrieb:
> Hi,
>
> I was trying to extend a Qt class in C++ and using this in my Python
> application. I got problems importing the python module:
>
> I was extending QListViewItem to QListViewItemNumeric. Then I used the
> following to generate the python extension:
>
> $ gcc -c -I/usr/include/qt3 -I/usr/include/python2.3
> QListViewItemNumeric.cpp
>
> Then I used swig with an interface file:
> -- snip --
> %module QListViewItemNumeric
> %{
> #include <qlistview.h>
> #include "QListViewItemNumeric.h"
> %}
> class QListViewItemNumeric : public QListViewItem {
> public:
> QListViewItemNumeric( QListView * parent );
> virtual void setNumeric( int columns = 0 );
> };
> -- pins --
>
> And compiled the result:
>
> $ swig -c++ -python QListViewItemNumeric.i \
> QListViewItemNumeric.i:6: Warning(401): Nothing known about class
> 'QListViewItem'. Ignored.
>
> $ gcc -c -I/usr/include/qt3 -I/usr/include/python2.3 \
> QListViewItemNumeric_wrap.cxx
>
> And linked both together with qt:
>
> $ gcc -shared QListViewItemNumeric.o QListViewItemNumeric_wrap.o -lqt -o \
> _QListViewItemNumeric.so
>
>
> When I omitted the "-lqt" python import told me:
> ImportError: ./_QListViewItemNumeric.so: undefined symbol:
> _ZN13QListViewItemC2EP9QListView
>
> which I figured out from the manual means I have to link it against the Qt
> library. I am not sure wether "-lqt" is the right thing to do.
>
> However, using the "-lqt" switch I now get a:
>
>
>>>>import QListViewItemNumeric
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "QListViewItemNumeric.py", line 5, in ?
> import _QListViewItemNumeric
> ImportError: ./_QListViewItemNumeric.so: undefined symbol:
> _ZTV20QListViewItemNumeric
>
>
> Can anyone help me over these first steps of using swig?
Unless you insist on using swig (in that case, I can't help you), you
might want to try out sip (www.riverbankcomputing.co.uk/sip) to work
with Qt and Python. To find out how to get your (own) Qt classes to work
with Python, you can have a look at the interface files of PyQt, there
are plenty of examples.
greets
Torsten
More information about the Python-list
mailing list