Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1648

QAbstractItemModel.createIndex() overload lead to crash when passing int as internalPointer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.12.0, 6.0.0, 6.1.1
    • PySide, Shiboken
    • None
    • Windows

      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>
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            t.rzepka Tobias Rzepka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes