Results 1 to 3 of 3

Thread: QMenu, QActions calling slots with an parameter?

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    4
    Qt products
    Qt4

    Default QMenu, QActions calling slots with an parameter?

    Hi i have a QMenu which is used as a popup menu.
    This menu contains a sub menu which can contain up to 10 sub menu items which are added dynamicaly. I would like to call the same slot from this 10 submenu items when triggered, but with an id parameter (1-10). How can i do this? When creating the menu action i can only do something like this menu->addAction("Menu item 1",this,SLOT(dowork(int))).
    how can i make the action do something like this: menu->addAction("Menu item 1",this,SLOT(dowork(1))) ?
    Is there a way to tell the action to send a parameter to the slot?
    Last edited by conti; 14th March 2012 at 12:50.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMenu, QActions calling slots with an parameter?

    There are at least two ways, but the simpler one would be to use QSignalMapper.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    conti (14th March 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    4
    Qt products
    Qt4

    Default Re: QMenu, QActions calling slots with an parameter?

    The QSignalMapper worked, thanks.

Similar Threads

  1. Replies: 5
    Last Post: 17th November 2010, 17:29
  2. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 13:18
  3. Draggable QActions in Qt
    By vajindarladdad in forum Newbie
    Replies: 6
    Last Post: 14th August 2009, 11:15
  4. Invisible but still active QActions
    By barnabyr in forum Newbie
    Replies: 6
    Last Post: 21st November 2006, 20:22
  5. Tooltips on QActions
    By drhex in forum Newbie
    Replies: 1
    Last Post: 8th February 2006, 18:05

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.