Results 1 to 5 of 5

Thread: QMenu connect to quit slot

  1. #1
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QMenu connect to quit slot

    Hi!

    This is my first post so I want to say hello to everyone.
    I have a question. Is there a way to connect QMenu to slot quit or close? I known how to connect QAction but what I should do if I want close app by clicking on QMenu? A signal aboutToShow is bad for this purpose. Do you have any suggestions?

    Hostel

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMenu connect to quit slot

    Hi,

    you can. Use qApp the get a pointer to your application and call the quit slot. It is like any other connection you make.

    Lykurg

  3. #3
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu connect to quit slot

    I tryed something like this:

    connect(ui->qmenuClose,SIGNAL(aboutToShow()), QApplication::instance(), SLOT(quit()));

    But when I had a QMenuBar with two QMenu for example qmenu1, and qmenuClose and then click on qmenu1, and then move cursor over qmenuClose then application will close without click.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMenu connect to quit slot

    That's because you are using the wrong signal on the wrong object. I suspect ui->qmenuClose is a QMenu, so use the actual action. Then use the triggered() signal. Thus the application only gets closed if you click the "button".

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

    Hostel (18th October 2010)

  6. #5
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu connect to quit slot

    Thanks for advice - I think that now I known how do this.

    Thanks again
    Last edited by Hostel; 18th October 2010 at 22:01.

Similar Threads

  1. Can't connect a signal to a slot
    By cejohnsonsr in forum Newbie
    Replies: 5
    Last Post: 26th August 2010, 20:42
  2. connect a qpushbutton a slot
    By Lycus HackerEmo in forum Newbie
    Replies: 13
    Last Post: 29th March 2010, 09:14
  3. qmenu and dynamic slot
    By mero in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2010, 13:51
  4. Replies: 2
    Last Post: 23rd April 2009, 07:15
  5. QObject::connect: No such slot !?!
    By Mystical Groovy in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 18:31

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.