swig problem

Uwe Mayer merkosh at hadiko.de
Mon Feb 16 13:24:22 CET 2004


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?

Thanks
Uwe



More information about the Python-list mailing list