Qt World Summit: Register Today!

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

  • 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:


    And that works just fine.

    Changing that line to
    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):


    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>
    File "c:\Python34\Lib\site-packages\PyQt5\ui.py", line 34, in setupUi
    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

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

    Changing to

    (basically just prefixing it with 'lambda:')

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

  • Lifetime Qt Champion

    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

Log in to reply