Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Connect(self.method) does not emit a signal, but (lambda: self.method()) does?
Forum Updated to NodeBB v4.3 + New Features

Connect(self.method) does not emit a signal, but (lambda: self.method()) does?

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Alabaster
    wrote on last edited by
    #1

    Suddenly my QPushButtons (which used to work perfectly) have decided not to emit signals (either that or their signals are not connecting properly?). I can't figure out what I changed which caused it to "break."

    I have found that the buttons do emit a signal when I use: button.clicked.connect(lambda: self.method()) -- but when I use button.clicked(self.method) there is no response. (Unfortunately using the lambda version breaks a lot of my remaining code which relies on self.sender()).

    Here is how this portion of my script is structured:

    My Central Widget has a grid layout (self.grid). I populate the grid with several rows of (dynamically generated) buttons & widgets. Each row is its own instance of my class EntryRow(QWidget).

    Here is the relevant method of my Central Widget:

    @
    def populateMainContent(self):

        self.getPageSettings()
        for index, thingy in enumerate(self.dummyData.dataDict[self.selectedThingies]):
            rowNum = index
            
     newRow = EntryRow(thingy, self.dummyData, self.grid, rowNum)
    
            mainWidgets = newRow.createMainWidgets()
            pageWidgets = newRow.createPageWidgets(self.selectedWidgets)
    
            widgetsToShow = mainWidgets + pageWidgets
    
            newRow.displayWidgets(widgetsToShow)@
    

    And here is my class EntryRow(QWidget) :

    @
    class EntryRow(QWidget):
    def init(self, name, dummyData, grid, rowNum):
    super().init()

        self.name = name
        self.widgetList = {"Main" : [],
                           "theseWidgets" : [],
                           "noIMeanThoseWidgets" : []
                           }
        self.grid = grid
        self.rowNum = rowNum
        self.dummyData = dummyData
    
    def createMainWidgets(self):
        self.nameLabel = QLabel(self.name)
        self.widgetList["Main"].append(self.nameLabel)
        return self.widgetList["Main"]
    
    def createPageWidgets(self, selectedWidgets):
        for widName in self.dummyData.widgetDict[selectedWidgets]:
            if "Button" in widName:
                newWidget = QPushButton(widName)
    

    newWidget.setCheckable(True)
    elif "Check" in widName:
    newWidget = QCheckBox(widName)

     ###########################################################
            newWidget.clicked.connect(self.method)  ## DOES NOT SEEM TO EMIT A SIGNAL
     ##########################################################
     #newWidget.clicked.connect(lambda: self.method())  # THIS DOES EMIT A SIGNAL
     ##########################################################
    
            self.widgetList[selectedWidgets].append(newWidget)
        return self.widgetList[selectedWidgets]
    
    def displayWidgets(self, widgetsToShow):
        for index, wid in enumerate(widgetsToShow):
            colNum = index
            self.grid.addWidget(wid, self.rowNum, colNum )
    
    def method(self):
        print("Signal received")
    

    @

    Any help would be appreciated. I assume it's a problem of parentage or layout?

    Thanks

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      Try decorating the slot as follows:

      @
      ...
      @QtCore.Slot
      def method(self):
      print("Signal received")
      ...
      @

      Hope this helps ;o)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      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