Results 1 to 4 of 4

Thread: Unable to send signal from QPushButton created in Python loop

  1. #1
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default Unable to send signal from QPushButton created in Python loop

    I am trying to create a series of buttons in a loop. Each button gets an id number as it's text and when the button is clicked it is supposed to send the id number to a function that will open an archived order. At this time I just want to print the order number to prove that the signal works and each button is connected to the correct order number.

    ui.cmdOpen = QtWidgets.QPushButton(ui.frOrdHist)
    ui.cmdOpen.setGeometry(QtCore.QRect(269, line1Y, 61, 22))
    ui.cmdOpen.setText(iOrderId)
    ui.cmdOpen.setObjectName("cmdOpen")
    ui.cmdOpen.clicked.connect(lambda button=ui.cmdOpen:displayOrder(ui, button))


    def displayOrder(ui, button):
    i = button.text()
    print(i)

    When I click the button, I get an error message that says "boolean object has no text attribute"

    I tried passing the order number directly and it would print "False" so still a boolean. I don't know where the boolean is coming from, it must be something wrong in the signal.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to send signal from QPushButton created in Python loop

    No idea about Python lambdas but you could use a QButtonGroup and simply connect to the group's buttonClicked() signal.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Unable to send signal from QPushButton created in Python loop

    It's most likely your lambda definition that is causing this confusion. The signal is correct and that boolean is coming from the signal's standard parameter. Have a look at : http://doc.qt.io/qt-5/qabstractbutton.html#clicked
    As far as I remember your button parameter will be overwritten with that boolean, so you should rather do something like this:
    Qt Code:
    1. ui.cmdOpen.clicked.connect(lambda state, button=ui.cmdOpen:displayOrder(button))
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Killian for this useful post:

    nlgootee (3rd November 2016)

  5. #4
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default Re: Unable to send signal from QPushButton created in Python loop

    That is pretty much the correct answer, the code that works is:

    ui.cmdOpen.clicked.connect(lambda checked, button=ui.cmdOpen:displayOrder(button))

    The documentation states that the checkable state is false by default and if it is not checkable this should not be an issue, so I don't understand where this comes from. I use lots of pushbuttons without this problem but this is the only one that I have that passes an argument.

Similar Threads

  1. Unable to send database file over LAN
    By webjack in forum Newbie
    Replies: 1
    Last Post: 7th October 2013, 21:15
  2. Unable to see the table created by QTableWidget
    By swathisri in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2013, 13:15
  3. Use python widget created with PyQt4 in Qt applications
    By alizadeh91 in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2012, 21:33
  4. Unable to send SMS
    By Manjula in forum Newbie
    Replies: 0
    Last Post: 11th March 2011, 11:40
  5. Unable to view images in an application created for Windows ce
    By mistertwister in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 4th March 2010, 19:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.