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. TableWidget.insertRow(1) fails inside connect() call
QtWS25 Last Chance

TableWidget.insertRow(1) fails inside connect() call

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 1.7k 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.
  • C Offline
    C Offline
    caver456
    wrote on last edited by
    #1

    Newbie question: I used pyuic5 to get a .py file of a simple test-case gui from Designer:

    -two widgets, one dialog

    • widget 1: table with 2 rows and 2 columns
    • widget 2: push button, intended to add a row to the table on each push

    In Designer, the insertRow mehtod does not exist as an option, so I saved the .ui and made the .py from it using the selectAll slot instead; the corresponding line in the generated .py is:

        self.pushButton.clicked.connect(self.tableWidget.selectAll)
    

    And that works just fine.

    Changing that line to
    self.pushButton.clicked.connect(self.tableWidget.insertRow)
    also works and adds a row at the top; but, I'd like to add a row at the bottom, something line .insertRow(self.tableWidget.rowCount) but as a first test I just tried .insertRow(1):

        self.pushButton.clicked.connect(self.tableWidget.insertRow(1))
    

    and this returns an error:

    c:\Python34\Lib\site-packages\PyQt5>python dialog.py
    Traceback (most recent call last):
    File "dialog.py", line 8, in <module>
    uio.setupUi(window)
    File "c:\Python34\Lib\site-packages\PyQt5\ui.py", line 34, in setupUi
    self.pushButton.clicked.connect(self.tableWidget.insertRow(1))
    TypeError: argument 1 has unexpected type 'NoneType'

    Any idea why that's happening? No doubt this is a newbie mistake, but, any info to help resolve it would be much appreciated. Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      caver456
      wrote on last edited by
      #2

      Solved it with the help of "this":http://qt-project.org/forums/viewthread/17393 post.

      Changing to
      self.pushButton.clicked.connect(lambda:self.tableWidget.insertRow(1))

      (basically just prefixing it with 'lambda:')

      solves it; I didn't realize connect() expects a reference to a function. Yup, a newbie problem indeed.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        It's rather that you are giving the slot a parameter. You also can't connect a parameterless signal to a slot with parameter.

        Anyway, for your purpose the use of a lambda is perfectly fine

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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