Results 1 to 3 of 3

Thread: Created sub-menus slots won't work

  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Created sub-menus slots won't work

    I have created two sub menus in my save button using the code below.

    Qt Code:
    1. QMenu *menu = new QMenu(this);
    2.  
    3. QAction *saveAction = menu->addAction("Save New");
    4. QAction *editAction = menu->addAction("Save Edits");
    5.  
    6. ui.saveButton->setMenu(menu);
    7.  
    8. connect(saveAction, SIGNAL(triggered()), this, SLOT(saveNew()));
    9. connect(editAction, SIGNAL(triggered()), this, SLOT(saveEdits()));
    To copy to clipboard, switch view to plain text mode 

    The project compiles without any errors but when i click any of the sub-menus i have created,the saveAction or the editAction slots won't execute.

    What i am i doing wrong?.

  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: Created sub-menus slots won't work

    Did you not forget to use the 'slots' or Q_SLOTS in your header?
    Are you slots private perhaps?
    Is the slot signature correct?
    ==========================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:

    thefatladysingsopera (7th September 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Created sub-menus slots won't work

    Also, check your app console output, Qt will print warning messages if connect statement is not correct (invalid signal / slot names etc).

  5. The following user says thank you to stampede for this useful post:

    thefatladysingsopera (7th September 2011)

Similar Threads

  1. Context Menus
    By qtoptus in forum Newbie
    Replies: 0
    Last Post: 25th June 2010, 15:18
  2. Replies: 15
    Last Post: 13th June 2010, 10:04
  3. signals and slots and menus problem in designer
    By hollowhead in forum Qt Tools
    Replies: 0
    Last Post: 5th March 2010, 17:31
  4. Accessible menus
    By NickPoole in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2009, 09:30
  5. Problem Getting User-Defined Signals/Slots to Work
    By Radiotelephone in forum Newbie
    Replies: 2
    Last Post: 3rd August 2009, 07:14

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.