Does anybody know of a way to obtain a custom type from a PyObject* representing that type, assuming it is registered with PythonQt and all that? e.g., Can I have the following:
MyType*get_object(PyObject*o){...}
I would like to be able to do this because I can't cleanly overload my function to have something like:
MyType*get_object(PyObject*o){
... Dostufftoo...
MyType*myTypeO=toMyType(o); // How can I do this?returnmyTypeO;
}
MyType*get_object(MyType*o){
... Dostufftoo...
returno;
}
With this overload in my CPP decorator class, PythonQt always seems to prefer to run the first method, even if the argument is of MyType*. I could simply not have a method version that takes a PyObject* argument to avoid the ambiguity, but then I'd be unable to pass in the Python types that I need.
Last edit: Flower lady 2019-12-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you tried changing the order of the slots? The more specific overload
needs to come first, I think. But yes, you can do a type check for PythonQt
wrappers and get the wrapped ptr from a wrapper. There is no example, but
you can see it in PythonQtConversion and PythonQtClassInfo how to do this.
Does anybody know of a way to obtain a custom type from a PyObject*
representing that type, assuming it is registered with PythonQt and all
that? e.g., Can I have the following:
MyType* get_object(PyObject* o){
...
}
I would like to be able to do this because I can't cleanly overload my
function to have something like: MyType* get_object(PyObject* o){
... Do stuff to o...
MyType* myTypeO = toMyType(o); // How can I do this?
return myTypeO;
}
MyType* get_object(MyType* o){
... Do stuff to o...
return o;
}
With this overload in my CPP decorator class, PythonQt always seems to
prefer to run the first method, even if the argument is of MyType*. I
could simply not have a method version that takes a PyObject* argument to
avoid the ambiguity, but then I'd be unable to pass in the Python types
that I need.
Thanks Florian, can't believe it was as simple as switching the order! I'll look into PythonQtConversion should the need arise, but I think I'm all set!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi folks,
Does anybody know of a way to obtain a custom type from a
PyObject*
representing that type, assuming it is registered with PythonQt and all that? e.g., Can I have the following:I would like to be able to do this because I can't cleanly overload my function to have something like:
With this overload in my CPP decorator class, PythonQt always seems to prefer to run the first method, even if the argument is of
MyType*
. I could simply not have a method version that takes aPyObject*
argument to avoid the ambiguity, but then I'd be unable to pass in the Python types that I need.Last edit: Flower lady 2019-12-27
Have you tried changing the order of the slots? The more specific overload
needs to come first, I think. But yes, you can do a type check for PythonQt
wrappers and get the wrapped ptr from a wrapper. There is no example, but
you can see it in PythonQtConversion and PythonQtClassInfo how to do this.
On Fri 27. Dec 2019 at 06:02, Flower lady fancyflowerlady@users.sourceforge.net wrote:
Thanks Florian, can't believe it was as simple as switching the order! I'll look into
PythonQtConversion
should the need arise, but I think I'm all set!I should add that I've tried:
But unfortunately, this doesn't seem to work, since I don't have a foreign wrapper factory (I'm not even sure what that is).
Thanks!