Two way Pushbutton issue
-
i mtrying to create a recstart/stop pushbutton but it works only the first time also in stop i open a dir to save it . the first and the second time it works correctly the third time i pressed it it open the dir twice(in rec stop function) instead run the recStart function the fourt time i pressed it opens th dir 4 times. I cant find a way to fix it
def recStart(self): if self.computationThread.isRunning(): self.rec = fast.StreamToFileExporter.create( str(QStandardPaths.writableLocation(QStandardPaths.DesktopLocation))).connect(self.filter) self.rec.setRecordingFolderName("recording1") self.renderer.connect(self.rec) self.ui.recButton.clicked.connect(self.recStop) def recStop(self): self.renderer.connect(self.filter) saveFile = QFileDialog.getSaveFileName(self, "Save File") self.ui.recButton.clicked.connect(self.recStart)
-
@Giakara
Are you saying you callrecStart
/Stop()
more than once? They haveconnect()
s in them. Aren't you going to end up with with multiple connections? Normally one doesconnect()
s just once, after the signalling/slot objects are created, not more than that. Is that what you are talking about?What you seem to be doing with reconnecting between
recStart
/Stop()
is not the best way to do it. But if you do choose to go down this route you must disconnect explicitly the old slot if you intend to replace the connection with a different slot.... -
@Giakara
That would be better!Remember that every signal can be connected to multiple slots, and vice versa. And (unless you specify otherwise in the
connect()
then default is) connecting even the same slot to the same signal does not get ignored and does not replace the connection, it adds a new connection, so you end up with the one signal calling multiple instances of the slot, which sounds like what you had. That's why doingconnect()
s basically only once at object initialisation time is advised.