On Wednesday 10 April 2002 17:29, you wrote:
> If you can't modify the C++ code to return a Python list, you will
> need to write %MemberCode (following foo's declaration in the .sip
> file) to accomplish that (I'm sure Phil will correct me if I'm
> wrong). "ListType" can be any name you choose. "sipCpp" and
> "sipCppPtr" in the PyQt/PyKDE2 examples are the pointers that
> represent the data to and from C++ respectively - use those names.
Thanks Jim for his kindly reply.I've created a vecstring.sip from qstrlist.sip
and a a.sip to wrap:
#include <vector>
#include <string>
using namespace std;
class A {
public: 
        A();
        ~A();
    void foo(const vector<string>&,vector<string>&);
};

The a.sip looks like:
%Module A
%Include vecstring.sip

%HeaderCode
#include "a.h"
%End

class A{
public:
void foo(const VecString&,VecString&);
};

and the vecstring.sip is in attachment.

The compile progress is ok with the following output:

/usr/local/bin/sip -s ".cpp" -c sip a.sip
cd sip && make
make[1]: Entering directory `/home/zl/prj/py/py/sip'
g++  -c -I.. -I. -I/usr/include/python2.1 -I/usr/local/include/sip  
Acmodule.cpp
g++  -c -I.. -I. -I/usr/include/python2.1 -I/usr/local/include/sip  sipAA.cpp
g++ -shared -L/usr/local/lib/ -lsip -o libAcmodule.so *.o
make[1]: Leaving directory `/home/zl/prj/py/py/sip'

When I try to import A from python interpreter a error occurs:

>>> import A
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    import A
  File "/home/zl/prj/py/py/sip2/A.py", line 5, in ?
    import libAc
ImportError: /home/zl/prj/py/py/sip2/libAcmodule.so: undefined symbol: 
sipConvertTo_VecString__FP7_objectPPt6vector2Zt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0Zt9allocator1Zt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0Pi
>>> import A

Seems like a linking problem but I'm not sure.
Can you tell me where is the problem?
-- 
                                        Sincerely yours,
                                                ejoy

// Copyright (c) 1998, 1999, 2000 Phil Thompson ([EMAIL PROTECTED])
//
// This is the SIP interface definition for QStrList.


%MappedType VecString
{
%HeaderCode
#include <vector>
#include <string>
using namespace std;
typedef vector<string> VecString;
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of strings.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> size())) == NULL)
		return NULL;

	// Get it.

	i = 0;

	VecString::iterator it;
	for (it = ((VecString *)sipCpp) -> begin(); it != ((VecString *)sipCpp) -> end(); it++)
	{
		PyObject *ps;

		if ((ps = PyString_FromString(it->c_str())) == NULL || PyList_SetItem(l,i,ps) < 0)
		{
			Py_XDECREF(ps);
			Py_DECREF(l);
			return NULL;
		}

		++i;
	}

	return l;
%End

//%CanConvertToTypeCode
//	return PyList_Check(sipPy);
//%End

%ConvertToTypeCode
	// Convert a Python list of strings to a QStrList on the heap.

	if (sipPy == Py_None)
	{
		//sipCheckNone(sipWillDeref,sipIsErr,sipName_VecString);
		*sipCppPtr = NULL;

		return 0;
	}

	VecString *plist = new VecString;

	for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
	{
		char *s;

		if ((s = PyString_AsString(PyList_GET_ITEM(sipPy,i))) == NULL)
		{
			*sipIsErr = 1;
			delete plist;

			return 0;
		}

		plist -> push_back(s);
	}

	*sipCppPtr = plist;

	return 1;
%End
};

Reply via email to