You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to adapt some code that used Boost.Python with custom type converters for "pointer only" types, in particular Qt types such as QObject, QWidget, etc., by interfacing with sip. It's not the cleanest code but it worked fine with Boost.Python converter.
With pybind11, I cannot get the casters to work... I tried writing a custom type caster for QWidget* (the pointer, not the object), but I feel like it's never used... If I try to wrap something like:
m.def("foo", [](QWidget* w) { ... });
And call it from Python, I get:
TypeError: foo(): incompatible function arguments. The following argument types are supported:
1. (arg0: QWidget) -> None
And if I accept a raw object and try to .cast<QWidget*>(), I get an error
RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)
Is there any documentation on how to write "pointer only" type like that? I already know how to extract the proper pointer from the python handle and back if needed, but I simply cannot get pybind11 to use the type casters I write.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to adapt some code that used Boost.Python with custom type converters for "pointer only" types, in particular Qt types such as
QObject
,QWidget
, etc., by interfacing with sip. It's not the cleanest code but it worked fine with Boost.Python converter.With pybind11, I cannot get the casters to work... I tried writing a custom type caster for
QWidget*
(the pointer, not the object), but I feel like it's never used... If I try to wrap something like:m.def("foo", [](QWidget* w) { ... });
And call it from Python, I get:
And if I accept a raw
object
and try to.cast<QWidget*>()
, I get an errorIs there any documentation on how to write "pointer only" type like that? I already know how to extract the proper pointer from the python handle and back if needed, but I simply cannot get pybind11 to use the type casters I write.
Beta Was this translation helpful? Give feedback.
All reactions