Description
createIndex is still unpythonic as already mentioned in PYSIDE-893 and PYSIDE-883 and there is a high potential to crash the Python interpreter!
When using a string or an other Qt object as third parameter, everything seems ok but if you want to pass an integer, it's interpreted as address pointer. Because internalPointer() ALWAYS assumes, that a python object is referenced and try to restore it. If the user tries for example to assign the integer 42 as third parameter, internalPointer() crashes Python.
The mentioned workarounds doesn't feel pythonic either.
Because in the C-world, you have to use a void pointer to reference an arbitrary value type but in the Python-world everything is a PyObject.
Therefore I would propose to remove the signature with quintptr completely and change the ptr to be optional.
PS: Using id(<object>) instead of VoidPtr is a little more convenient, but still not pythonic and an implementation detail of id(). E.g.:
>>> index <PySide2.QtCore.QModelIndex(3,3,0x0,SimpleModel(0x213adb9cd80)) at 0x00000213AE53FA40> >>> hex(id(index)) '0x213ae53fa40' >>> idx = mdl.createIndex(0, 1, id(index)) >>> idx.internalPointer() <PySide2.QtCore.QModelIndex(3,3,0x0,SimpleModel(0x213adb9cd80)) at 0x00000213AE53FA40>
Attachments
Issue Links
- relates to
-
PYSIDE-893 Qt 5.12: QAbstractItemModel::createIndex method input parameter
- Closed
-
PYSIDE-2762 Wrong type hint for QModelIndex.internalPointer
- Closed