Important: Please read the Qt Code of Conduct -

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(
    def recStop(self):
        saveFile = QFileDialog.getSaveFileName(self, "Save File")

  • @Giakara
    Are you saying you call recStart/Stop() more than once? They have connect()s in them. Aren't you going to end up with with multiple connections? Normally one does connect()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....

  • maybe the best way is with one function and some flag i ll try this way

  • @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 doing connect()s basically only once at object initialisation time is advised.

Log in to reply