PDA

View Full Version : QMenu connect to quit slot



Hostel
17th October 2010, 23:52
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

Lykurg
17th October 2010, 23:55
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

Hostel
18th October 2010, 00:02
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.

Lykurg
18th October 2010, 08:45
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".

Hostel
18th October 2010, 22:51
Thanks for advice - I think that now I known how do this.

Thanks again :)