0

I have a Qt main window where I call another window, actually a kind of submenu wich contains parameters for the first one; here is a part of this main window :

void Ui_MainWindow::createSignals()
{ 
  connect(actionDisk_galaxy, SIGNAL(triggered()), this,  SLOT(ICMenu()));
}

void Ui_MainWindow::ICMenu()
{
qmenu = new QMainWindow;
DiskMenu = new Ui_DiskGalMenu;
DiskMenu->setupUi(qmenu,this);
setInitialDiskMenuPosition(qmenu, this);
qmenu->show();
}

As you can see, I call another QMainwindow ("qmenu"); here's the code of this new window (whose type is "Ui_DiskGalMenu"):

void Ui_DiskGalMenu::createMenuSignals()
{
  connect(pushButton_4, SIGNAL(clicked()), this, SLOT(closeMenu()));       
}

void Ui_DiskGalMenu::closeMenu()
{  
close(true);
} 

After setting parameters in this sub-menu, I would like to close it with a pushButton (here "pushButton_4").

My problem is that when I click on "pushButton_4", this window doesn't close.

I have also tried to reimplement closeEvent but without success.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

This function call looks like a mistake:

close(true);

QWidget::close() doesn't take any parameters. So what you're doing here, is call the close(int) function of the C library (for closing file descriptors.) bool is implicitly converted to int, so you end up with this call:

::close(1);

Which is (probably) closing stderr.

You can see what's happening if you change the above to:

this->close(true);

You should get a compilation error since no such function exists. So the correct call would have been:

this->close();

However, QWidget::close() is already a slot, so you don't need the Ui_DiskGalMenu::closeMenu() function at all. All you need is connect to the close() slot to begin with:

connect(actionDisk_galaxy, SIGNAL(triggered()), this, SLOT(close()));

If you need to do more stuff when the window closes, you can override closeEvent() which will be called before the window gets closed.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96