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. [Solved] PyQt Signals
Qt 6.11 is out! See what's new in the release blog

[Solved] PyQt Signals

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

    Hi,

    When I put this piece of code in my PyQt python script:

    @widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function(param))@

    It complains this error:

    bq. widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function(param))
    TypeError: argument 3 of QObject.connect() has an invalid type

    Is there any way I can have my function with parameters or is the only way:

    @widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function)@

    Thanks!!


    http://abstrusegoose.com/432

    1 Reply Last reply
    0
    • N Offline
      N Offline
      needhelp_gh
      wrote on last edited by
      #2

      Any thoughts? Please & thank you!


      http://abstrusegoose.com/432

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tw55413
        wrote on last edited by
        #3

        try :

        comboBox.activated.connect( function )

        1 Reply Last reply
        0
        • N Offline
          N Offline
          needhelp_gh
          wrote on last edited by
          #4

          Thanks for the reply!

          I tried this:

          @def test(num):
          print num
          ...
          comboBox.activated.connect( test(1) )@

          Got this error:

          connect() slot argument should be a callable or a signal, not 'NoneType'


          http://abstrusegoose.com/432

          1 Reply Last reply
          0
          • N Offline
            N Offline
            needhelp_gh
            wrote on last edited by
            #5

            Any other ideas?

            Thx!!


            http://abstrusegoose.com/432

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

              The connect function expects a reference to a function, what you are doing is passing it the result of a function. The simple case is:

              @comboBox.activated.connect(test)@

              If you want to pass a parameter to the slot function then you need to use a lambda as follows:

              @comboBox.activated.connect(lambda: test(1))@

              If you want to pass a variable rather than a static value then:

              @
              x=10
              comboBox.activated.connect(lambda: test(x))
              @

              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
              • N Offline
                N Offline
                needhelp_gh
                wrote on last edited by
                #7

                Thanks so much for the reply/answer :) It works!!!


                http://abstrusegoose.com/432

                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