Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8183827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:17:18+00:00 2026-06-07T01:17:18+00:00

In follow up to Create PyQt menu from a list of strings i’m also

  • 0

In follow up to Create PyQt menu from a list of strings i’m also creating menu’s on the fly and want to know which menu item was clicked. Therefore I used a piece of code like:

for item in ADDABLE_OBJECTS:
     action = self.menuAdd.addAction(item)
     l = lambda item=item: self.doStuff(item)
     action.triggered.connect(l)

def doStuff(self, item):
  print "Item: ", item

Ouput:

Item: False (default ‘bool’ param as stated in Qt Docs for triggered() signal)

As I thought that object.connect() is the ‘new’ form as compared to connect(object, SIGNAL(…), slot). I also works better as the signal names can be checked at compile time.
However, it did not work. All I got passed was the ‘bool=false’ (as stated in the Qt docs for triggered()). So after searching came across the above mention url. No I have this:

for item in ['One', 'Two', 'Three']:
    action = self.menuAdd.addAction(item)
    l = lambda item=item: self.doStuff(item)
    action.triggered.connect(l)
    self.connect(action, SIGNAL('triggered()'), l)

Which gives (on clicking the menu once):

Item: False (the action.triggered.connect(l) line, wrong)
Item: One (the self.connect line, right)

Why do these two behave different? I have never noticed any difference between the two kinds of connect before, not until I used this lambda construction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:17:20+00:00Added an answer on June 7, 2026 at 1:17 am

    It is not about the lambda, but rather how the signals with default arguments are implemented in Qt.

    void triggered(bool = 0)
    

    is actually two signals:

    void triggered(bool)
    void triggered()
    

    PyQt docs mention the default overload for this signal as triggered(bool) and since your function accepts an argument it can successfully connect this signal to your function. Therefore the bool parameter is passed for the item.

    You can choose specific overloads by indexing syntax. In this case you want the signal with no parameters, so you would do:

    action.triggered[()].connect(l)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create query follow. select member.name,depratment.name from member left join depratment on
I am trying to create an array which will follow something like this array(
I want to create 1MB String for benchmark,so I writed code as follow: public
I'm trying to follow a guide from http://kellabyte.com/2010/11/13/building-extensible-wcf-service-interfaces-with-datacontractresolver/ to create and attach a DataContractSerializer.
I am using GTranslate from google I already follow the steps create account and
I try to create database from entity framework code first follow with this tutorial
I follow this tutorial to create a svn http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/ However after running $ svn
I'm trying to create and follow best practices for versioning control and came across
I create a constructor as follow Form1(array<System::String ^> ^args) //HW5 { InitializeComponent(); // //TODO:
I'm trying to follow the instructions located at How-To Create a Hello World Snap-in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.