Segmentation fault after emiting a signal
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi Florian,
First run the following:
Now pass the dictionary
m
through the Signal/Slot mechanism -- its value is correctly printed by the connected slot.However a segmentation fault is raised when
m
is next referenced:My theory is that the dictionary object is being freed somewhere along the way; doing the following in
PythonQtSignal.cpp
appears to fix things.Python output:
The following though will crash:
Thanks,
Dave
It works if I change
to
so I think you found a bug in the reference counting when PyObject is usedin signal/slot connections.
I have to think about this, it requires some extra ref/decref at the right places.
I fixed this on svn trunk. It was indeed a missing ref-count on the PyObject, but in the signal receiver call (I never had a signal with a PyObject before).
It turns out that the reference has to be counted before the PyObject is passed to the slot, not when the object is received. (A local variable, passed to
emit()
may well be deleted by the time the slot method is called...).The code added to
PythonQtSignalTarget::call()
needs to be removed, and instead, line 114 ofPythonQtSlot.cpp
replaced with:As in aside, have you given serious consideration to using GitHub for PythonQt? IMHO, using GitHub would greatly simplify working on the code base!