Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QPushButton clicked connect strange behavior
QtWS25 Last Chance

QPushButton clicked connect strange behavior

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 266 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.
  • F Offline
    F Offline
    ForeverNoob
    wrote on last edited by
    #1

    Hello,

    Got the following code:

    class NoteManagerClass(QMainWindow):
    
        def __init__(self):
            super().__init__()
    
            # Widgets
            newNoteButton = QPushButton("New Note")
            newNoteButton.clicked.connect(self.newNote())        # This actually calls the newNote() function
            .
            . more lines
            .
    
        def newNote(self):
            print("New Note")
    
    

    The problem: when the script reaches the button connect function, it executes the newNote function, but later, when the button is clicked, that function isn't called. Not sure whats going on.

    (Sorry in advance for possibly stupid question, newbie in both Qt and python)

    TIA

    Chris KawaC 1 Reply Last reply
    0
    • F ForeverNoob

      Hello,

      Got the following code:

      class NoteManagerClass(QMainWindow):
      
          def __init__(self):
              super().__init__()
      
              # Widgets
              newNoteButton = QPushButton("New Note")
              newNoteButton.clicked.connect(self.newNote())        # This actually calls the newNote() function
              .
              . more lines
              .
      
          def newNote(self):
              print("New Note")
      
      

      The problem: when the script reaches the button connect function, it executes the newNote function, but later, when the button is clicked, that function isn't called. Not sure whats going on.

      (Sorry in advance for possibly stupid question, newbie in both Qt and python)

      TIA

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This actually calls the newNote() function

      Yes, because you called it (used the () operator). You're supposed to pass the function address, not call it i.e.

      newNoteButton.clicked.connect(self.newNote)  
      
      F 1 Reply Last reply
      2
      • F ForeverNoob has marked this topic as solved on
      • Chris KawaC Chris Kawa

        This actually calls the newNote() function

        Yes, because you called it (used the () operator). You're supposed to pass the function address, not call it i.e.

        newNoteButton.clicked.connect(self.newNote)  
        
        F Offline
        F Offline
        ForeverNoob
        wrote on last edited by
        #3

        @Chris-Kawa said in QPushButton clicked connect strange behavior:

        This actually calls the newNote() function

        Yes, because you called it (used the () operator). You're supposed to pass the function address, not call it i.e.

        newNoteButton.clicked.connect(self.newNote)  
        

        Right, it works now. Thanks a bunch.

        1 Reply Last reply
        0

        • Login

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