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
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
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.
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".
Re: QMenu connect to quit slot
Thanks for advice - I think that now I known how do this.
Thanks again :)