Qt for Python/Shiboken

From Qt Wiki
< Qt for Python
Revision as of 11:37, 2 April 2021 by FKosmale (talk | contribs) (shiboken documentation has moved)
Jump to: navigation, search

Shiboken (Shi bō ken, 死某剣) is the Python binding generator that Qt for Python uses to create the PySide module, in other words, is the system we use to expose the Qt C++ API to Python.

The name Shiboken2 and PySide2 make reference to the Qt 5 compatibility, since the previous versions (without the 2) refer to Qt 4.

The process

Relation between Qt, Shiboken and PySide

Shiboken uses an ApiExtractor library (based on an old project called QtScriptGenerator) to parse the Qt Headers and get the information of all the Qt classes, using Clang. This step is not Qt-dependent, so it can be use for other C++ projects as well.

Additionally, Shiboken has a Typesystem (based on XML) which allows modifying the obtained information to properly represent and manipulate the C++ classes into the Python World.

Through this Typesystem we can remove and add methods to certain classes, and even modify the arguments of each function, which is really necessary when both C++ and Python collide and a decision needs to be made to properly handle the data structures or types.

The outcome of this process is a set of wrappers written in CPython, which allow us to easily compile and then provide you the python module called PySide2.