Closing widget
Unsolved
General and Desktop
-
Hi,
I'm having some problems with a connect command. I've been using the qtdesigner so far and everything worked. Now I need to code it manually. The problem is the mainwindow close but I need to close the child widget. Here's the code.
void MainWindow::on_actionKundensuche_triggered() { QWidget *window = new QWidget; QPushButton *button1 = new QPushButton("OK"); QPushButton *button2 = new QPushButton("Abbrechen"); QLineEdit *line1 = new QLineEdit(); window->setFixedSize(300, 250); QVBoxLayout *layout1 = new QVBoxLayout; layout1->addWidget(line1); QHBoxLayout *layout2 = new QHBoxLayout; layout2->addWidget(button1); layout2->addWidget(button2); layout1->addLayout(layout2); window->setLayout(layout1); window->show(); connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered())); } void MainWindow::on_abbrechen_triggered() { close(); }
-
@tactical77 said in Closing widget:
connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered()));
After this do something like this:
connect(button2, SIGNAL(clicked()), window, SLOT(deleteLater()));
-
@tactical77 said in Closing widget:
void MainWindow::on_abbrechen_triggered()
{
close();
}If you want to close the widget why do you call close() on your MainWindow?
Call close on your widget instead:void MainWindow::on_abbrechen_triggered() { window->close(); }