Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Two way Pushbutton issue
Forum Updated to NodeBB v4.3 + New Features

Two way Pushbutton issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 345 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Giakara
    wrote on last edited by
    #1

    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)
    
    JonBJ 1 Reply Last reply
    0
    • G Giakara

      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)
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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....

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Giakara
        wrote on last edited by
        #3

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

        JonBJ 1 Reply Last reply
        0
        • G Giakara

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved