swig problem

U

Uwe Mayer

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:
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
 
T

Torsten Marek

Uwe said:
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:



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
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top