#14899: Hide main windows on close instead of deleting them

WA_DeleteOnClose left RiuMainWindow::instance() and RiuPlotMainWindow::instance() null after the user closed a window, so any unguarded use crashed. Keep both windows alive for the application lifetime and rebuild their views when a closed window is shown again.

Fixes #14899.
This commit is contained in:
Magne Sjaastad authored and JJ committed 2026-10-12 17:23:10 +02:00
1 parent 6ff9a5b46d
commit f0dc8c47f0
7 files changed
+99 -9

No files matched your search

@@ -93,6 +93,7 @@ RiuMainWindowBase::RiuMainWindowBase()
, m_blockSubWindowProjectTreeSelection( false )
, m_hasBeenVisible( false )
, m_isBeingDestroyed( false )
, m_hasBeenClosed( false )
, m_windowMenu( nullptr )
{
ads::CDockManager::setAutoHideConfigFlags( ads::CDockManager::DefaultAutoHideConfig );
@@ -283,6 +284,9 @@ void RiuMainWindowBase::saveWinGeoAndDockToolBarLayout()
// https://github.com/OPM/ResInsight/issues/9935
if ( !m_hasBeenVisible ) return;
// The views were removed from docking when the window was closed, and the state was saved before that
if ( m_hasBeenClosed ) return;
// Company and appname set through QCoreApplication
QSettings settings;
@@ -863,9 +867,27 @@ void RiuMainWindowBase::closeEvent( QCloseEvent* event )
view->removeWindowFromDock();
}
m_hasBeenClosed = true;
QMainWindow::closeEvent( event );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuMainWindowBase::hasBeenClosed() const
{
return m_hasBeenClosed;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowBase::clearClosedState()
{
m_hasBeenClosed = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------