Results 1 to 5 of 5

Thread: Is there a simpler way to send the same signal from many objects?

  1. #1
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Is there a simpler way to send the same signal from many objects?

    Hello,

    I plan to use menus in my applications. There are many menus and sub menus. Only one sub menu needs one specified status. When I click other menus or sub menus I hope to change the status to normal one. But I do not hope to connect all of the menus or sub menus to the triggered signal.

    Is there some smarter ways to resolve this problem? I mean just one line.

    just like this:

    if (x is triggered)
    status changs
    else
    status changes back

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Is there a simpler way to send the same signal from many objects?

    Could you explain more clearly what you mean by "status"? Does it refer to the presence of a checkbox next to the menu item?

    If you have several menu item that are to do similar things, just with a different parameter, check out QSignalMapper.

  3. #3
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Is there a simpler way to send the same signal from many objects?

    Thanks for you reply.

    My question is like this:

    There Menu1 that consists of sub menuA , sub menuB and so on
    Menu2 that consists of sub menu AA, sub menu BB and so on
    Menu3 that consists of sub menu AAA, sub menu BBB and so on
    ... ....

    When I click the sub menu AA, The value of status becomes true. But when I click any other menu except sub menu AA, I hope the value of status will become false. I do not hope to connect each sub menu with the signal because there are too many sub menus.
    connect(menuAction, SIGNAL(triggered()), this, SLOT(valueChanged));

    My question is: Is there some way we can do it in a simpler way?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is there a simpler way to send the same signal from many objects?

    did you see this signal QMenu::triggered.
    an example
    Qt Code:
    1. ...
    2. QMenu *menu = menuBar()->addMenu("Test");
    3. QAction *action = new QAction("1", this);
    4. menu->addAction(action);
    5. action = new QAction("2", this);
    6. menu->addAction(action);
    7. action = new QAction("3", this);
    8. menu->addAction(action);
    9. action = new QAction("4", this);
    10. menu->addAction(action);
    11. action = new QAction("5", this);
    12. menu->addAction(action);
    13.  
    14. connect(menu, SIGNAL(triggered(QAction *)), SLOT(processAction(QAction *)));
    15. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a simpler way to send the same signal from many objects?

    Have you looked at QActionGroup - I think you make a group of QActions mutually exclusive.

    Pete

Similar Threads

  1. Replies: 5
    Last Post: 28th April 2009, 00:29
  2. send own class reference throught signal
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2008, 22:55
  3. Can you send a signal to a thread?
    By Dumbledore in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 21:31
  4. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 16:03
  5. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 15:18

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.