{"id":3275,"library":"shiboken6","title":"Shiboken6: Python/C++ Bindings Helper","description":"Shiboken6 is a core component of Qt for Python (PySide6), responsible for generating Python bindings for C++ libraries. It enables seamless, low-level interaction between Python and C++ objects, allowing Python to call C++ functions and access C++ data structures directly. It is currently at version 6.11.0 and is actively maintained, with updates released in conjunction with PySide6 and Qt releases.","status":"active","version":"6.11.0","language":"en","source_language":"en","source_url":"https://github.com/qt-project/pyside-setup","tags":["qt","pyside","bindings","cpp","interop","low-level"],"install":[{"cmd":"pip install shiboken6","lang":"bash","label":"Install Shiboken6"}],"dependencies":[],"imports":[{"note":"For Qt6/PySide6, the module name is 'shiboken6'. 'shiboken' refers to the Qt5/PySide2 era.","wrong":"from shiboken import wrapInstance","symbol":"wrapInstance","correct":"from shiboken6 import wrapInstance"},{"note":"For Qt6/PySide6, the module name is 'shiboken6'. 'shiboken' refers to the Qt5/PySide2 era.","wrong":"from shiboken import getCppPointer","symbol":"getCppPointer","correct":"from shiboken6 import getCppPointer"}],"quickstart":{"code":"from shiboken6 import getCppPointer, wrapInstance\n# PySide6 is required to run this example. Install with: pip install PySide6\nfrom PySide6.QtCore import QObject \n\n# Shiboken6 is typically used with PySide6 objects\nobj = QObject()\nobj.setObjectName(\"MyQObject\")\n\n# Get the underlying C++ pointer from a PySide6 object\ncpp_ptr_long = getCppPointer(obj)\nprint(f\"Python QObject: {obj}\")\nprint(f\"C++ pointer (long): {cpp_ptr_long:#x}\")\n\nprint(\"\\n--- Conceptual use of wrapInstance ---\")\nprint(\"wrapInstance is used to convert a raw C++ pointer into a Python object.\")\nprint(\"Example: `python_object = wrapInstance(raw_cpp_ptr, PySide6.ClassName, ownership=shiboken6.Ownership.CppOwnership)`\")\nprint(\"It requires a valid C++ pointer (e.g., from an external C++ library call)\")\nprint(\"and the expected PySide6 class type for correct wrapping. Careful memory\")\nprint(\"management with `shiboken6.Ownership` is crucial to prevent crashes or leaks.\")","lang":"python","description":"Shiboken6 is primarily used for low-level interaction between Python and C++ objects, specifically within the Qt/PySide ecosystem. This example demonstrates how to retrieve the underlying C++ pointer from a PySide6 QObject using `getCppPointer`. While `wrapInstance` is also a key function, its typical use involves receiving a raw C++ pointer from an external C++ source, which is difficult to simulate in a simple, self-contained Python snippet. Note that `PySide6` is a prerequisite to run this quickstart."},"warnings":[{"fix":"Update all `import shiboken` or `from shiboken import ...` statements to use `shiboken6` instead. For example, `from shiboken import wrapInstance` becomes `from shiboken6 import wrapInstance`.","message":"When migrating from PySide2/Qt5 to PySide6/Qt6, the Shiboken module name changed from `shiboken` to `shiboken6`. Direct imports or references to `shiboken` will result in `ModuleNotFoundError`.","severity":"breaking","affected_versions":"<6.0.0"},{"fix":"Always explicitly define `ownership` when using `wrapInstance`. For C++-managed objects, use `ownership=shiboken6.Ownership.CppOwnership`. For objects where Python should take ownership and manage its lifecycle, use `ownership=shiboken6.Ownership.PythonOwnership`.","message":"Using `shiboken6.wrapInstance` incorrectly, especially regarding memory ownership, can lead to memory leaks, double-frees, or application crashes. If `ownership` is not handled correctly, Python's garbage collector might attempt to delete a C++ object managed externally or prematurely.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure you understand the purpose of `shiboken6`. For standard GUI development, interact primarily with the PySide6 API. Reserve direct `shiboken6` usage for advanced scenarios involving raw C++ pointers or custom C++ extensions that integrate with PySide6.","message":"Shiboken6 is a low-level binding tool; it is not intended for general application development. Directly interacting with `shiboken6` beyond simple debugging with `getCppPointer` or specific C++/Python interoperability for custom extensions often indicates a deeper misunderstanding or an overly complex solution.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}