Shiboken::ObjectType Namespace

namespace Shiboken::ObjectType

Namespace for object type-related functionality. More...

Header: #include <basewrapper.h>

Functions

bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType)
(since 6.8) bool canDowncastTo(PyTypeObject *baseType, PyTypeObject *targetType)
void *cast(PyTypeObject *sourceType, SbkObject *obj, PyTypeObject *pyTargetType)
bool checkType(PyTypeObject *type)
void *getTypeUserData(PyTypeObject *type)
bool hasCast(PyTypeObject *type)
bool hasSpecialCastFunction(PyTypeObject *sbkType)
PyTypeObject *introduceWrapperType(PyObject *enclosingObject, const char *typeName, const char *originalName, PyType_Spec *typeSpec, ObjectDestructor cppObjDtor, PyObject *bases, unsigned int wrapperFlags = 0)
bool isUserType(PyTypeObject *type)
void setCastFunction(PyTypeObject *type, SpecialCastFunction func)
void setSubTypeInitHook(PyTypeObject *type, SubTypeInitHook func)
void setTypeUserData(PyTypeObject *type, void *userData, DeleteUserDataFunc d_func)
PyTypeObject *typeForTypeName(const char *typeName)

Detailed Description

Function Documentation

bool ObjectType::canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType)

Returns true if the constructor of ctorType can be called for an instance of type myType.

Note: This function sets a Python error when returning false.

[since 6.8] bool ObjectType::canDowncastTo(PyTypeObject *baseType, PyTypeObject *targetType)

Returns whether a C++ pointer of the Python type baseType of the base class can be safely downcast to the Python type targetType of the derived class (base is a direct, single-line base class of targetType).

This function was introduced in Qt 6.8.

void *ObjectType::cast(PyTypeObject *sourceType, SbkObject *obj, PyTypeObject *pyTargetType)

Cast the C++ pointer held by a Python object obj of type sourceType, to a C++ pointer of a C++ class indicated by type pyTargetType and return the cast C++ pointer.

bool ObjectType::checkType(PyTypeObject *type)

Returns true if the object of type is an instance of a type created by the Shiboken generator.

void *ObjectType::getTypeUserData(PyTypeObject *type)

Returns the user data of type previously set by Shiboken::ObjectType::setTypeUserData().

bool ObjectType::hasCast(PyTypeObject *type)

Returns true if the type represents an object of a class with multiple inheritance in C++. When this occurs, the C++ pointer held by the Python wrapper will need to be cast when passed as a parameter that expects a type of its ancestry.

This means a call to ObjectType::cast() is needed to obtain the correct C++ pointer for Python objects of type type.

bool ObjectType::hasSpecialCastFunction(PyTypeObject *sbkType)

Returns whether the PyTypeObject sbkType has a special cast function (multiple inheritance).

PyTypeObject *ObjectType::introduceWrapperType(PyObject *enclosingObject, const char *typeName, const char *originalName, PyType_Spec *typeSpec, ObjectDestructor cppObjDtor, PyObject *bases, unsigned int wrapperFlags = 0)

Initializes a Shiboken wrapper type and adds it to the module, or to the enclosing class if the type is an inner class. This function also calls setDestructorFunction().

ParameterMeaning
enclosingObjectThe module or enclosing class to which the new type will be added.
typeNameName by which the type will be known in Python.
originalNameOriginal C++ name of the type.
typeSpecThe new type to be initialized and added to the module.
cppObjDtorMemory deallocation function for the C++ object held by the type. Should not be used if the underlying C++ class has a private destructor.
basesBase types from which the new type inherits.
wrapperFlagsFlags, see WrapperFlags.

Returns the new type or nullptr if the initialization failed.

bool ObjectType::isUserType(PyTypeObject *type)

Returns true if this object of type is an instance of a user-defined type derived from a Shiboken type.

void ObjectType::setCastFunction(PyTypeObject *type, SpecialCastFunction func)

Sets the C++ cast function for type to func.

void ObjectType::setSubTypeInitHook(PyTypeObject *type, SubTypeInitHook func)

Sets the subtype init hook for type to func.

This hook will be invoked every time the user creates a sub-type inherited from a Shiboken based type. The hook gets 3 parameters: The new type being created, args and kwds. The last two are the same as passed to tp_new.

void ObjectType::setTypeUserData(PyTypeObject *type, void *userData, DeleteUserDataFunc d_func)

Sets the user data of type to userData. d_func is a function used to delete the user data.

PyTypeObject *ObjectType::typeForTypeName(const char *typeName)

Returns an instance of PyTypeObject for a C++ type name typeName as determined by typeinfo().name().