In a PyQt4 app I connect a slider to one or another slot depending on user actions. I change the slot assignment in response to button clicks. The several different slots do different things, too different to merge into one slot with some "if" statements.
This app crashes frequently. I am wondering if it's kosher to be reassigning slots to one signal on the fly like this. Could this lead to dangling pointers internal to PyQt4, memory corruption, or something else bad? If what I'm doing is okay, I will look elsewhere for the bug.
Here's a very sketch version of my app:
def MyThing(QWidget):
(in some approprate place)
self.s = QSlider()
def MethodOne(self): # this is a slot handling a button click
self.s.valueChanged.connect(self.someslot1)
def MethodTwo(self): # likewise
self.s.valueChanged.connect(self.someslot2)
def someslot1(self, svalue): # slider movement handler
(compute, show info based on slider position)
def someslot2(self, svalue): # similar to someslot1
....
If the 2 connected objects still exist when you call connect, that shouldn't cause a crash by itself.
According to your code, you don't seem to disconnect the previously connected slots (with self.s.valueChanged.disconnect()
for instance), and that can cause both slots to be called multiple times for each signal, which means that your application could slow down with time, and might crash depending on what you do in the slots.