I have my own class based in QWidget. I put this widget in QMainWindow and I need catch mouse click on this widget.
I tried:
connect(my_widget, SIGNAL(clicked()), this, SLOT(exit(0)));
But nothing is happening. How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
QWidget does not have a clicked() signal, and QMainWindow does not have an exit() slot. It is impossible to connect to an unexisting signal and unexisting slot. The return value of the connect must be true if the connect is successful. Check this value when you make connections to be sure that your code will work correctly.
To exit your application, you must call
qApp->quit()Also, as it has been mentioned by others, you will have to install an eventFilter or reimplement the
or
methods.
There are plenty of examples in the official doc of Qt, this for example reimplements the
mousePressEvent(QMouseEvent *event)method.For the eventFilter option, see this small example.
Hope this helps.