473,385 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

swig problem

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
1 2185
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt Whelan | last post by:
Supposedly, recent versions of SWIG can be made to work with MS VC++'s non-standard integer data types. According to a recent SWIG ChangeLog entry: %apply long long { __int64 }; should make...
0
by: Jon Moldover | last post by:
Hi, I'm using Python in my win32 app by linking to the python23.dll. I'm trying to expose some c++ code in my app to Python so I can make application calls from Python scripts (according to the...
0
by: Oliver Tengler | last post by:
Hi, I wrap the following code with SWIG: class Bar {}; class Foo { public: const Bar* getBar() { return &m_bar; }
0
by: Andrew Collier | last post by:
hello, i am not sure whether this problem relates to swig, python or my c++ compiler. +please forgive me if this is inappropriately posted but i am sure that someone +on this list must have some...
3
by: Lars Moastuen | last post by:
Im trying to extend a class written in C++ in Python and use this extended class in a C++ call... I made an example to clarify: -- Foo.h -- #ifndef FOO_H #define FOO_H #include <iostream>...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
10
by: Bart Ogryczak | last post by:
Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it...
0
by: Frank | last post by:
Hi, I have the following problem: I want to call a cpp program from python. Let's call this cpp program fct. The problem is that I will parse a large array, say M1, to fct and also receive a...
1
by: cody314 | last post by:
Versions: Python 2.5.1 (r251:54863, May 14 2007, 10:50:04) SWIG Version 1.3.20 Hello I have some code that wraps a C++ library so I may use it in python. The code basically just gets some data...
1
by: Stodge | last post by:
Yet another SWIG question (YASQ!). I'm having a problem with using an abstract base class. When generating the Python bindings, SWIG thinks that all the concrete classes that derive from this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.