main window close not working
new on forum, be gentle, thx for help.
qt version 4.6.2
This is code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
closeButton = new QPushButton("close");
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
setCentralWidget(closeButton);
bool x = false;
// here is problem
if ( !x )
close();
}
Q: why doesn't MainWindow closes?
Re: main window close not working
Very simple.
In the doc it says:
Quote:
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First it sends the widget a QCloseEvent.
And a close event will be accepted by a visible widget.
A widget gets to be visible after it got a QShowEvent, and since you are still in the constructor, no such event has been received, hence the widget is not yet visible, hence, no effect of close().
Re: main window close not working
Code:
#include<qapplication.h>
connect(closeButton, SIGNAL(clicked()), qApp, SLOT(quit()));
this works