PythonQt
Public Member Functions | Public Attributes | List of all members
PythonQtInstanceWrapper Struct Reference

a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects) More...

#include <PythonQtInstanceWrapper.h>

Public Member Functions

PyObject_HEAD PythonQtClassInfoclassInfo ()
 the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers More...
 
PythonQtDynamicClassInfodynamicClassInfo ()
 
void setQObject (QObject *object)
 set the QObject pointer More...
 
void passOwnershipToCPP ()
 Passes the ownership of the wrapped object to C++. More...
 
void passOwnershipToPython ()
 Passes the ownership to Python. More...
 

Public Attributes

QPointer< QObject > _obj
 pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr More...
 
void * _objPointerCopy
 
void * _wrappedPtr
 optional C++ object Ptr that is wrapped by the above _obj More...
 
bool _ownedByPythonQt
 flag that stores if the object is owned by pythonQt More...
 
bool _useQMetaTypeDestroy
 stores that the owned object should be destroyed using QMetaType::destroy() More...
 
bool _isShellInstance
 stores if the object is a shell instance More...
 
bool _shellInstanceRefCountsWrapper
 stores if the shell instance (C++) owns the wrapper with its ref count More...
 

Detailed Description

a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects)

Definition at line 62 of file PythonQtInstanceWrapper.h.

Member Function Documentation

◆ classInfo()

PyObject_HEAD PythonQtClassInfo* PythonQtInstanceWrapper::classInfo ( )
inline

the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers

Definition at line 66 of file PythonQtInstanceWrapper.h.

67  { return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }

◆ dynamicClassInfo()

PythonQtDynamicClassInfo* PythonQtInstanceWrapper::dynamicClassInfo ( )
inline

Definition at line 69 of file PythonQtInstanceWrapper.h.

70  { return ((PythonQtClassWrapper*)Py_TYPE(this))->_dynamicClassInfo; }

◆ passOwnershipToCPP()

void PythonQtInstanceWrapper::passOwnershipToCPP ( )
inline

Passes the ownership of the wrapped object to C++.

Definition at line 79 of file PythonQtInstanceWrapper.h.

79  {
80  // we pass the ownership to C++
81  _ownedByPythonQt = false;
82  // handle shell instance
83  if (_isShellInstance) {
85  // ref count the wrapper, so that the Python part of the shell instance can not go
86  // away until the C++ object gets deleted...
87  Py_INCREF((PyObject*)this);
89  }
90  }
91  }
struct _object PyObject
bool _shellInstanceRefCountsWrapper
stores if the shell instance (C++) owns the wrapper with its ref count
bool _ownedByPythonQt
flag that stores if the object is owned by pythonQt
bool _isShellInstance
stores if the object is a shell instance

References _isShellInstance, _ownedByPythonQt, and _shellInstanceRefCountsWrapper.

◆ passOwnershipToPython()

void PythonQtInstanceWrapper::passOwnershipToPython ( )
inline

Passes the ownership to Python.

Definition at line 94 of file PythonQtInstanceWrapper.h.

94  {
95  _ownedByPythonQt = true;
96  // if the shell instance was owned by C++ and the ownership goes to Python,
97  // we need to remove the extra ref count that kept the Python part alive from the C++ side.
99  Py_DECREF((PyObject*)this);
101  }
102  }

References _ownedByPythonQt, and _shellInstanceRefCountsWrapper.

◆ setQObject()

void PythonQtInstanceWrapper::setQObject ( QObject *  object)
inline

set the QObject pointer

Definition at line 73 of file PythonQtInstanceWrapper.h.

73  {
74  _obj = object;
75  _objPointerCopy = object;
76  }
QPointer< QObject > _obj
pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr

References _obj, and _objPointerCopy.

Member Data Documentation

◆ _isShellInstance

bool PythonQtInstanceWrapper::_isShellInstance

stores if the object is a shell instance

Definition at line 123 of file PythonQtInstanceWrapper.h.

Referenced by passOwnershipToCPP().

◆ _obj

QPointer<QObject> PythonQtInstanceWrapper::_obj

pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr

Definition at line 106 of file PythonQtInstanceWrapper.h.

Referenced by setQObject().

◆ _objPointerCopy

void* PythonQtInstanceWrapper::_objPointerCopy

a copy of the _obj pointer, which is required because the wrapper needs to deregister itself via the _obj pointer, even when the QPointer<QObject> object was destroyed

Definition at line 109 of file PythonQtInstanceWrapper.h.

Referenced by setQObject().

◆ _ownedByPythonQt

bool PythonQtInstanceWrapper::_ownedByPythonQt

flag that stores if the object is owned by pythonQt

Definition at line 117 of file PythonQtInstanceWrapper.h.

Referenced by passOwnershipToCPP(), passOwnershipToPython(), and PythonQtConvertListOfKnownClassToPythonList().

◆ _shellInstanceRefCountsWrapper

bool PythonQtInstanceWrapper::_shellInstanceRefCountsWrapper

stores if the shell instance (C++) owns the wrapper with its ref count

Definition at line 126 of file PythonQtInstanceWrapper.h.

Referenced by passOwnershipToCPP(), and passOwnershipToPython().

◆ _useQMetaTypeDestroy

bool PythonQtInstanceWrapper::_useQMetaTypeDestroy

stores that the owned object should be destroyed using QMetaType::destroy()

Definition at line 120 of file PythonQtInstanceWrapper.h.

◆ _wrappedPtr

void* PythonQtInstanceWrapper::_wrappedPtr

optional C++ object Ptr that is wrapped by the above _obj

Definition at line 112 of file PythonQtInstanceWrapper.h.


The documentation for this struct was generated from the following file: