By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

swig problem

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.