[C++-sig] Boost::Signals

David Abrahams dave at boost-consulting.com
Thu Jun 15 17:44:20 CEST 2006


John Reid <johnbaronreid at netscape.net> writes:

> Hi,
>
> 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 
> following error:
>
> 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 
> module::classname

Actually that would be namespacename::classname.  It's a C++ class
name, most probably of the return type of the C++ function
implementing your connect_new_deal_slot_py_2 method.  Another
possibility is that it's the name of a C++ class of which you're
passing an instance to f inside that C++ function implementing
connect_new_deal_slot_py_2.  Either way, you haven't wrapped that C++
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."

I don't see how that relates to the error message you're seeing above.

> This is what I would like to do

which?  "tell the library to build a Python object around the
pointer?"  http://boost.org/libs/python/doc/v2/ptr.html#examples.

Ensuring the appropriate lifetime relationships is a more complicated
topic than I can explain here, though.          

> but cannot find this elsewhere in the 
> documentation. Can anyone let me know how to do this?
>
> Thanks in advance,
> John.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list