QWidget doesn't close when main window is closed
Asked Answered
P

2

10

I'm trying to make a main window (QWidget) which open a new QWidget when a button is clicked but when I close the main window, the QWidget recently opened doesn't close.

main.cpp

QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();

mainwindow.cpp (parent)

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

out.cpp (child)

Out::Out(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Out)
{
    ui->setupUi(this);

}
Platto answered 9/5, 2013 at 18:27 Comment(3)
Can you post the code?Knowling
They are a lot of lines, i don't know which part I must post.Platto
I would suggest you write as small an example as possible that reproduces the problem, and post that. But for starters, what does your main.cpp look like?Knowling
B
13

I suspect you're looking for Qt::WA_QuitOnClose:

Makes Qt quit the application when the last widget with the attribute set has accepted closeEvent(). This behavior can be modified with the QApplication::quitOnLastWindowClosed property. By default this attribute is set for all widgets of type Qt::Window.

In this case, you should probably call:

myWidget->setAttribute( Qt::WA_QuitOnClose, false );
Buffybuford answered 9/5, 2013 at 18:41 Comment(0)
L
1

This is for Python

Try to create a function like below

def func_quit_all_windows():
  sys.exit()

Remember to import sys

When the button is clicked call the function

btn.clicked.connect(func_quit_all_windows)
Libbey answered 24/10, 2020 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.