johnbaronreid at netscape.net
Tue Jun 6 22:46:14 CEST 2006
I'm trying to call a python function from C++. I pass the function to
C++ as a boost::python::object. I can call functions with no arguments,
when I try to pass a C++ created object as an argument I get the
Traceback (most recent call last):
File "python/test_python.py", line 8, in ?
d.connect_new_deal_slot_py_2( f )
TypeError: No to_python (by-value) converter found for C++ type: class
Now the boost.python section (http://tinyurl.com/n3cpv) in the python
wiki answers the following question:
"Is it is possible to convert pointers to existing classes to PyObjects*
and then be able to pass an existing instance of an object directly to
and from python?"
where the last paragraph says:
"If you really want to pass pointers around, it's certainly possible to
tell the library to build a Python object around the pointer, but then
you need to make sure the lifetime of the C++ object being referenced by
the pointer extends past the lifetime of all Python references to the
object or your program will crash."
This is what I would like to do but cannot find this elsewhere in the
documentation. Can anyone let me know how to do this?
Thanks in advance,
More information about the Cplusplus-sig