Fixing a segfault on 'xkill' - solution was to register an exit handler that cleanly shuts down

This commit is contained in:
Matthias Koefferlein 2026-04-20 22:19:56 +02:00
parent 5ccf6260f1
commit 9ad273d834
5 changed files with 21 additions and 4 deletions

View File

@ -1658,6 +1658,12 @@ GuiApplication::event (QEvent *event)
return QApplication::event(event);
}
static void atexit_handler ()
{
if (lay::ApplicationBase::instance ()) {
lay::ApplicationBase::instance ()->shutdown ();
}
}
int
GuiApplication::exec ()
@ -1693,6 +1699,10 @@ GuiApplication::exec ()
}
// register an exit handler to shutdown cleanly in case of an explicit exit
// inside the code
::atexit (&atexit_handler);
return QApplication::exec ();
}

View File

@ -105,6 +105,15 @@ public:
*/
void exit (int result);
/**
* @brief Shut down the application
*
* Calling this function will close the main window and
* prepare for exit. Unlike "exit", it dows not actually exit
* the process.
*/
virtual void shutdown ();
/**
* @brief Return the program's version
*/
@ -330,7 +339,6 @@ public:
protected:
virtual void setup () = 0;
virtual void shutdown ();
virtual void prepare_recording (const std::string &gtf_record, bool gtf_record_incremental);
virtual void start_recording ();
virtual lay::Dispatcher *dispatcher () const = 0;

View File

@ -165,7 +165,6 @@ show_dock_widget (QDockWidget *dock_widget, bool visible)
MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
: QMainWindow (0),
tl::Object (),
lay::DispatcherDelegate (),
m_dispatcher (this),
m_text_progress (this, 10 /*verbosity threshold*/),

View File

@ -94,7 +94,6 @@ class ProgressWidget;
*/
class LAY_PUBLIC MainWindow
: public QMainWindow,
public tl::Object,
public gsi::ObjectBase,
public lay::DispatcherDelegate
{

View File

@ -49,6 +49,7 @@ class ConfigureAction;
* @brief A delegate by which the dispatcher can submit notification events
*/
class LAYBASIC_PUBLIC DispatcherDelegate
: public tl::Object
{
public:
/**
@ -271,7 +272,7 @@ private:
#if defined(HAVE_QT)
QWidget *mp_menu_parent_widget;
#endif
DispatcherDelegate *mp_delegate;
tl::weak_ptr<DispatcherDelegate> mp_delegate;
};
}