On 10/22/2012 09:19 AM, Luiz Vitor Martinez Cardoso wrote:
Anyone?
On Sun, Oct 14, 2012 at 3:54 PM, Luiz Vitor Martinez Cardoso
<[email protected] <mailto:[email protected]>> wrote:
Dear,
I'm new to PySide/Shiboken but I'm enjoying it!
To be honest I don't like the lack of good and reasonable documentation
and examples.
I decided to create a git repo
(https://github.com/Grabber/shiboken-binding-examples) together my friend
/Yann Lanthony /to archive all the solutions we get to work in our lab. At
the end we plan to write a very detailed and extensive article including
everything from the installation (Win, OSX and Linux) to the binding
process itself.
Today the master's help to solve a little trouble.
I'm trying to wrap the following code:
class LIBFOO_EXPORT CustomType
{
public:
CustomType() {}
virtual ~CustomType() {}
CustomType(const CustomType&) {}
int a;
int * b;
};
Using the following TypeSystem:
<?xml version="1.0"?>
<typesystem package="foo">
<primitive-type name="int"/>
<load-typesystem name="typesystem_core.xml" generate="no"/>
<object-type name="CustomType" />
</typesystem>
But I'm getting some pointers erros in the generated wrapping code:
/home/lmvc/Projects/shiboken-binding-examples/build/foo/foo/customtype_wrapper.cpp:
In function 'PyObject* Sbk_CustomType_get_b(PyObject*, void*)':
/home/lmvc/Projects/shiboken-binding-examples/build/foo/foo/customtype_wrapper.cpp:166:33:
error: invalid conversion from 'int*' to 'int' [-fpermissive]
/home/lmvc/Projects/shiboken-binding-examples/build/foo/foo/customtype_wrapper.cpp:
In function 'int Sbk_CustomType_set_b(PyObject*, PyObject*, void*)':
/home/lmvc/Projects/shiboken-binding-examples/build/foo/foo/customtype_wrapper.cpp:187:33:
error: invalid conversion from 'int*' to 'int' [-fpermissive]
/home/lmvc/Projects/shiboken-binding-examples/build/foo/foo/customtype_wrapper.cpp:189:18:
error: invalid conversion from 'int' to 'int*' [-fpermissive]
make[2]: *** [foo/CMakeFiles/foo.dir/foo/customtype_wrapper.cpp.o]
Error 1
The generated wrapping code was:
static PyObject* Sbk_CustomType_get_b(PyObject* self, void*)
{
::CustomType* cppSelf = 0;
SBK_UNUSED(cppSelf)
if (!Shiboken::Object::isValid(self))
return 0;
cppSelf =
((::CustomType*)Shiboken::Conversions::cppPointer(SbkfooTypes[SBK_CUSTOMTYPE_IDX],
(SbkObject*)self));
int cppOut_local = cppSelf->b;
PyObject* pyOut =
Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(),
&cppOut_local);
return pyOut;
}
static int Sbk_CustomType_set_b(PyObject* self, PyObject* pyIn, void*)
{
::CustomType* cppSelf = 0;
SBK_UNUSED(cppSelf)
if (!Shiboken::Object::isValid(self))
return 0;
cppSelf =
((::CustomType*)Shiboken::Conversions::cppPointer(SbkfooTypes[SBK_CUSTOMTYPE_IDX],
(SbkObject*)self));
if (pyIn == 0) {
PyErr_SetString(PyExc_TypeError, "'b' may not be deleted");
return -1;
}
PythonToCppFunc pythonToCpp;
if (!(pythonToCpp =
Shiboken::Conversions::isPythonToCppConvertible(Shiboken::Conversions::PrimitiveTypeConverter<int>(),
(pyIn)))) {
PyErr_SetString(PyExc_TypeError, "wrong type attributed to
'b', 'int' or convertible type expected");
return -1;
}
int cppOut_local = cppSelf->b;
pythonToCpp(pyIn, &cppOut_local);
cppSelf->b = cppOut_local;
return 0;
}
Could someone tell me what is going on? I feel I have to inject some code
in TypeSystem but I don't know well...
I appreciate your help!
Best regards,
Luiz Vitor.
Luiz,
I'm not certain, but since no one else jumped in, I believe it relates to int
being a primitive type. That is, it maps the types directly instead of using an
opaque pointer. I seem to recall there being similar issues [1] for me when I
tried to have a member array of primitives (which in C/C++ can be thought of as
a glorified pointer). The summary of the answer had to do with not being able to
keep track of updates to the pointer, or something like that.
I believe types specified as "value-type" are similar in that they are passed by
value.
Perhaps someone more knowledgeable can correct my simplistic answers.
Hope that helps
John Cummings
[1] http://thread.gmane.org/gmane.comp.lib.qt.pyside/2331/focus=2332
_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside