[PySide] Obtaining QObject from PySide based PyObject (complete)

Hugo Parente Lima hugo.lima at openbossa.org
Mon Aug 27 21:23:03 CEST 2012


On Monday, August 27, 2012 09:12:27 PM David García Garzón wrote:
> Sorry for the previous unfinished message. Here goes the final one.
> 
> I am porting a CPython library (boost based indeed) from PyQt to PySide.
> I had a function in the library that received a Sip wrapped widget
> as a PyObject and I used the very ugly SIP api to recover a pointer to the
> actual C++ QObject.
> 
> Does anyone know how recover the C++ QObject from the PyObject in PySide?

You can use:
Shiboken::Object::cppPointer(...), it's on libshiboken basewrapper.h

It receives two parameters, a SbkObject* and a PyTypeObject*, the SbkObject* 
will be your PyObject*, just cast it and make sure it always will be a Python 
object representing a C++ object bound using Shiboken, the PyTypeObject* must 
be the PyTypeObject* for QObject, you can get it using:

Shiboken::TypeResolver::get("QObject*")->pythonType();

TypeResolver class is located on libshiboken typeresolver.h header.

Hope this would help you.


> Thanks.
> David.
> 
> PS: If someone is curious the current sip unwrapper, based on some snippets
> i found, is in here:
> 	http://clam-project.org/clam/trunk/ipyclam/sipunwrap.cxx
> And the function  which uses it is bindUi in
> 	http://clam-project.org/clam/trunk/ipyclam/Clam_NetworkProxy.cxx
> 
> 
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120827/ed3d463e/attachment.sig>


More information about the PySide mailing list