Segfault when creating QVariant from Enum based Python class
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi,
Background
When running some Python code from PythonQt the other day, I got a segfault in PythonQtConversion.cpp. It turned out that when an Enum based class is processed by
PyObjToQVariant
, it's recognised as a sequence (since it's possible to iterate over an Enum in Python), butPySequence_GetItem
returns nullptr when the loop gets the value to add to the QVariantList, causing the segfault when callingPyObjToVariant
with a null pointer. Unless Enums should be treated in a special way, I assume that the best is to handle them as "normal" classes. In order to do that I created a small patch that checks ifval->ob_type->tp_name
is "EnumMeta". I'm not sure if this is an acceptable solution, so I'm open for better ways to fix it.Python 2.7 (with enum34 installed) and 3.6 behave the same.
Files
Supplied files:
Minimal example
Building
Building the test application (very manual – I ran this on Xubuntu 18.10):
Expected output
Without the patch, there is a segfault when running the minimal example. With the patch applied, it outputs this:
Links regarding Enum
Last edit: Erik Lundin 2018-11-21
I don't have time to fix this right now, but I added a bug report in our internal bug tracker.
Moved to https://github.com/MeVisLab/pythonqt/pull/1