QWidget doesn't close when main window is closed
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 );