I'm trying to implement an exit button, but I'm unable to use connect()
method to do this. Actually my button does not emit any signal as far as I know, but I can't find the problem.
Here is part of my code that uses connect()
method:
#include "MyMainWindow.h"
MyMainWindow::MyMainWindow(QWidget * parent, Qt::WindowFlags flag) :
QMainWindow(parent, flag)
{
this->setFixedSize(1120, 630);
menu = new MyMenu(this);
this->setCentralWidget(menu);
this->show();
// the connect implementation
connect(menu->exit, SIGNAL(clicked()), this, SLOT(this->exit_button_clicked()));
}
MyMainWindow::~MyMainWindow()
{
}
void MyMainWindow::exit_button_clicked()
{
this->close();
}
MyMainWindow
is a friend class of MyMenu
and exit
is a private QPushButton
. Now I want some help for solving this problem.
You can use as below directly
connect(menu->exit, SIGNAL(clicked()), this, SLOT(close()));
There is no need to create new method exit_button_clicked()
as SLOT