Built-in Types

Primitive C++ Types

Shiboken knows the C++ primitive types like int and float and gathers information about typedefs like int32_t and size_t at runtime while parsing C++ headers. Function overloads using these types will be automatically generated. To suppress a primitive type, use the rejection tag.

In principle, there is no need to specify them in the typesystem file using the primitive-type tag.

However, specifying a type means that the type name is used for matching signatures of functions for modification. So, it might make sense to specify architecture-dependent types like size_t to avoid having to spell out the resolved type, which might differ depending on platform.

std::string, std::wstring and their associated view types std::string_view, std::wstring_view are also supported.

C++ Container Types

The C++ containers std::list, std::vector, std::pair, std::map, std::span and std::unordered_map are built-in. To specify Opaque Containers, use the opaque-container element. container-type can still be specified to modify the built-in behavior. For this case, a number of pre-defined conversion templates are provided (see Predefined Templates).

CPython Types

Python types like str match CPython types like PyUnicode in the Concrete Objects Layer of CPython. They have check functions like PyUnicode_Check(), which Shiboken generates into the code checking the function arguments.

The CPython types are built into Shiboken as custom types along with their check functions.

To generate functions taking such types as arguments, specify the CPython types in the signature specified on add-function or as or modified-type on replace-type.

This requires a code injection using the %PYARG_<number> type system variable to convert them to a C++ type for the call.

CPython types can also be used as type on add-conversion within a conversion-rule or as target language API types on primitive-type.

CPython Types

Name

Description

PyArrayObject

NumPy array

PyBool

Boolean value

PyBuffer

A type implementing the Buffer Protocol

PyByteArray

bytearray value

PyBytes

Bytes object

PyCallable

Callable object

PyComplex

Complex Number Object

PyDate

Date value

PyDateTime

Date time value

PyDict

Dictionary

PyFloat

Float value

PyLong

Long (integer) value

PyObject

Plain PyObject (typically used for optional parameters)

PyPathLike

Path from pathlib or string. The utility function PySide::pyPathToQString() (pysideutils.h) can be used to convert it to a QString.

PySequence

Sequence

PyTypeObject

Type object

PyUnicode

Unicode object

SbkChar

Unicode object of length 1 (matching the char type of C++).

str

Unicode object or None