# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1428116738 18000
# Node ID aba20a44815c9b18f025d54f2e5f29cadc734ad4
# Parent  cf9b94a89620cefbd2eb55ac242286252b69ef51
Reorganize Octave/Qt link and QMainWindow for --no-gui option (bug #44116)

* main-window.cc
(main_window::main_window): Pass pointer to octave_qt_link into constructor.
Remove _octave_qt_link and _start_gui initialization.  Call function that
makes all connections to link.  Restore code to CS# 19948:fc6c87e254bf.
(main_window::~main_window): Do not delete _octave_qt_link.
(main_window::main_window): Restore code to CS# 19948:fc6c87e254bf.  Emit a
shutdown signal rather than call _octave_qt_link members.
(main_window::construct): Remove construct_octave_qt_link.  Restore code to
CS# 19948:fc6c87e254bf.
(main_window::construct): Restore code to CS# 19948:fc6c87e254bf.
(main_window::construct_octave_qt_link): Renamed connect_octave_qt_link().
Do not construct octave_qt_link.  Restore code to CS# 19948:fc6c87e254bf.

* main-window.h
(main_window::main_window): Pass in octave_qt_link pointer rather than boolean.
Add shutdown_result() signal.  Rename member construct_octave_qt_link() to
connect_octave_qt_link().  Remove leftover establish_octave_link() declaration.
Remove _octave_qt_link and _start_gui member variables.

* octave-gui.cc
(octave_start_gui) Construct Octave/Qt link prior to handling GUI startup
cases.  Condition all QMainWindow code under one start_gui test.  Place
application.exec inside both cases.  For non-QMainWindow-app case make some
connections to satisfy shutdown-check and exit_app signals.

* octave-qt-link.cc: Add <QApplication> header.
(octave_qt_link::shutdown_confirmation): Define slot--set result, awake worker.
(octave_qt_link::feedback_shutdown): New slot--emit feedback_shutdown_result.
(octave_qt_link::feedback_exit_app): New slot--call QApplication exit().

* octave-qt-link.h (octave_qt_link): Move shutdown_confirmation slot definition
to octave-qt-link.cc.  Declare new signal feedback_shutdown_result() and two
new slots feedback_shutdown() and feedback_exit_app().

diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -73,21 +73,20 @@ create_default_editor (QWidget *p)
 #endif
 }
 
-main_window::main_window (QWidget *p, bool start_gui)
+main_window::main_window (QWidget *p, octave_qt_link *octqt_link)
   : QMainWindow (p),
-    _workspace_model (start_gui ? new workspace_model () : 0),
-    status_bar (start_gui ? new QStatusBar () : 0),
-    command_window (start_gui ? new terminal_dock_widget (this) : 0),
-    history_window (start_gui ? new history_dock_widget (this) : 0),
-    file_browser_window (start_gui ? new files_dock_widget (this) : 0),
-    doc_browser_window (start_gui ? new documentation_dock_widget (this) : 0),
-    editor_window (start_gui ? create_default_editor (this) : 0),
-    workspace_window (start_gui ? new workspace_view (this) : 0),
+    _workspace_model (new workspace_model ()),
+    status_bar (new QStatusBar ()),
+    command_window (new terminal_dock_widget (this)),
+    history_window (new history_dock_widget (this)),
+    file_browser_window (new files_dock_widget (this)),
+    doc_browser_window (new documentation_dock_widget (this)),
+    editor_window (create_default_editor (this)),
+    workspace_window (new workspace_view (this)),
     _settings_dlg (0),
     find_files_dlg (0),
     release_notes_window (0),
     community_news_window (0),
-    _octave_qt_link (0),
     _clipboard (QApplication::clipboard ()),
     _cmd_queue (QList<octave_cmd *> ()),  // no command pending
     _cmd_processing (1),
@@ -96,8 +95,7 @@ main_window::main_window (QWidget *p, bo
     _dbg_processing (1),
     _dbg_queue_mutex (),
     _prevent_readline_conflicts (true),
-    _suppress_dbg_location (true),
-    _start_gui (start_gui)
+    _suppress_dbg_location (true)
 {
   QSettings *settings = resource_manager::get_settings ();
 
@@ -120,12 +118,14 @@ main_window::main_window (QWidget *p, bo
   QDateTime current = QDateTime::currentDateTime ();
   QDateTime one_day_ago = current.addDays (-1);
 
-  if (start_gui && connect_to_web
+  if (connect_to_web
       && (! last_checked.isValid () || one_day_ago > last_checked))
     load_and_display_community_news (serial);
 
   // We have to set up all our windows, before we finally launch octave.
   construct ();
+
+  connect_octave_qt_link (octqt_link);
 }
 
 main_window::~main_window (void)
@@ -161,7 +161,6 @@ main_window::~main_window (void)
       delete community_news_window;
       community_news_window = 0;
     }
-  delete _octave_qt_link;
 }
 
 // catch focus changes and determine the active dock widget
@@ -774,30 +773,24 @@ main_window::confirm_shutdown_octave (vo
 {
   bool closenow = true;
 
-  if (_start_gui)
+  QSettings *settings = resource_manager::get_settings ();
+
+  if (settings->value ("prompt_to_exit", false).toBool ())
     {
-      QSettings *settings = resource_manager::get_settings ();
-
-      if (settings->value ("prompt_to_exit", false).toBool ())
-        {
-          int ans = QMessageBox::question (this, tr ("Octave"),
-                                           tr ("Are you sure you want to exit Octave?"),
-                                           QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
-
-          if (ans !=  QMessageBox::Ok)
-            closenow = false;
-        }
+      int ans = QMessageBox::question (this, tr ("Octave"),
+                                       tr ("Are you sure you want to exit Octave?"),
+                                       QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
+
+      if (ans !=  QMessageBox::Ok)
+        closenow = false;
+    }
 
 #ifdef HAVE_QSCINTILLA
-      if (closenow)
-        closenow = editor_window->check_closing ();
+  if (closenow)
+    closenow = editor_window->check_closing ();
 #endif
-    }
-
-  _octave_qt_link->shutdown_confirmation (closenow);
-
-  // Awake the worker thread so that it continues shutting down (or not).
-  _octave_qt_link->waitcondition.wakeAll ();
+
+  emit shutdown_result (closenow);
 }
 
 void
@@ -1316,96 +1309,92 @@ main_window::construct (void)
 
   connect_uiwidget_links ();
 
-  construct_octave_qt_link ();
-
-  if (_start_gui)
-    {
-      setWindowIcon (QIcon (":/actions/icons/logo.png"));
-
-      workspace_window->setModel (_workspace_model);
-      connect (_workspace_model, SIGNAL (model_changed (void)),
-               workspace_window, SLOT (handle_model_changed (void)));
-
-      construct_menu_bar ();
-
-      construct_tool_bar ();
-
-      connect (qApp, SIGNAL (aboutToQuit ()),
-               this, SLOT (prepare_to_exit ()));
-
-      connect (qApp, SIGNAL (focusChanged (QWidget*, QWidget*)),
-               this, SLOT(focus_changed (QWidget*, QWidget*)));
-
-      connect (this, SIGNAL (settings_changed (const QSettings *)),
-               this, SLOT (notice_settings (const QSettings *)));
-
-      connect (this, SIGNAL (editor_focus_changed (bool)),
-               this, SLOT (set_global_edit_shortcuts (bool)));
-
-      connect (this, SIGNAL (editor_focus_changed (bool)),
-               editor_window, SLOT (enable_menu_shortcuts (bool)));
-
-      connect (file_browser_window, SIGNAL (load_file_signal (const QString&)),
-               this, SLOT (handle_load_workspace_request (const QString&)));
-
-      connect (file_browser_window, SIGNAL (find_files_signal (const QString&)),
-               this, SLOT (find_files (const QString&)));
-
-      setWindowTitle ("Octave");
-
-      setDockOptions (QMainWindow::AnimatedDocks
-                      | QMainWindow::AllowNestedDocks
-                      | QMainWindow::AllowTabbedDocks);
-
-      addDockWidget (Qt::RightDockWidgetArea, command_window);
-      addDockWidget (Qt::RightDockWidgetArea, doc_browser_window);
-      tabifyDockWidget (command_window, doc_browser_window);
+  setWindowIcon (QIcon (":/actions/icons/logo.png"));
+
+  workspace_window->setModel (_workspace_model);
+  connect (_workspace_model, SIGNAL (model_changed (void)),
+           workspace_window, SLOT (handle_model_changed (void)));
+
+  construct_menu_bar ();
+
+  construct_tool_bar ();
+
+  connect (qApp, SIGNAL (aboutToQuit ()),
+           this, SLOT (prepare_to_exit ()));
+
+  connect (qApp, SIGNAL (focusChanged (QWidget*, QWidget*)),
+           this, SLOT(focus_changed (QWidget*, QWidget*)));
+
+  connect (this, SIGNAL (settings_changed (const QSettings *)),
+           this, SLOT (notice_settings (const QSettings *)));
+
+  connect (this, SIGNAL (editor_focus_changed (bool)),
+           this, SLOT (set_global_edit_shortcuts (bool)));
+
+  connect (this, SIGNAL (editor_focus_changed (bool)),
+           editor_window, SLOT (enable_menu_shortcuts (bool)));
+
+  connect (file_browser_window, SIGNAL (load_file_signal (const QString&)),
+           this, SLOT (handle_load_workspace_request (const QString&)));
+
+  connect (file_browser_window, SIGNAL (find_files_signal (const QString&)),
+           this, SLOT (find_files (const QString&)));
+
+  setWindowTitle ("Octave");
+
+  setDockOptions (QMainWindow::AnimatedDocks
+                  | QMainWindow::AllowNestedDocks
+                  | QMainWindow::AllowTabbedDocks);
+
+  addDockWidget (Qt::RightDockWidgetArea, command_window);
+  addDockWidget (Qt::RightDockWidgetArea, doc_browser_window);
+  tabifyDockWidget (command_window, doc_browser_window);
 
 #ifdef HAVE_QSCINTILLA
-      addDockWidget (Qt::RightDockWidgetArea, editor_window);
-      tabifyDockWidget (command_window, editor_window);
+  addDockWidget (Qt::RightDockWidgetArea, editor_window);
+  tabifyDockWidget (command_window, editor_window);
 #endif
 
-      addDockWidget (Qt::LeftDockWidgetArea, file_browser_window);
-      addDockWidget (Qt::LeftDockWidgetArea, workspace_window);
-      addDockWidget (Qt::LeftDockWidgetArea, history_window);
-
-      int win_x = QApplication::desktop ()->width ();
-      int win_y = QApplication::desktop ()->height ();
-
-      if (win_x > 960)
-        win_x = 960;
-
-      if (win_y > 720)
-        win_y = 720;
-
-      setGeometry (0, 0, win_x, win_y);
-
-      setStatusBar (status_bar);
+  addDockWidget (Qt::LeftDockWidgetArea, file_browser_window);
+  addDockWidget (Qt::LeftDockWidgetArea, workspace_window);
+  addDockWidget (Qt::LeftDockWidgetArea, history_window);
+
+  int win_x = QApplication::desktop ()->width ();
+  int win_y = QApplication::desktop ()->height ();
+
+  if (win_x > 960)
+    win_x = 960;
+
+  if (win_y > 720)
+    win_y = 720;
+
+  setGeometry (0, 0, win_x, win_y);
+
+  setStatusBar (status_bar);
 
 #ifdef HAVE_QSCINTILLA
-      connect (this,
-               SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
-               editor_window,
-               SLOT (handle_insert_debugger_pointer_request (const QString&, int)));
-
-      connect (this,
-               SIGNAL (delete_debugger_pointer_signal (const QString&, int)),
-               editor_window,
-               SLOT (handle_delete_debugger_pointer_request (const QString&, int)));
-
-      connect (this,
-               SIGNAL (update_breakpoint_marker_signal (bool, const QString&, int)),
-               editor_window,
-               SLOT (handle_update_breakpoint_marker_request (bool,
-                                                              const QString&,
-                                                              int)));
+  connect (this,
+           SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
+           editor_window,
+           SLOT (handle_insert_debugger_pointer_request (const QString&, int)));
+
+  connect (this,
+           SIGNAL (delete_debugger_pointer_signal (const QString&, int)),
+           editor_window,
+           SLOT (handle_delete_debugger_pointer_request (const QString&, int)));
+
+  connect (this,
+           SIGNAL (update_breakpoint_marker_signal (bool, const QString&, int)),
+           editor_window,
+           SLOT (handle_update_breakpoint_marker_request (bool,
+                                                          const QString&,
+                                                          int)));
 #endif
 
-      octave_link::post_event (this, &main_window::resize_command_window_callback);
-
-      configure_shortcuts ();
-    }
+  octave_link::post_event (this, &main_window::resize_command_window_callback);
+
+  configure_shortcuts ();
+
 }
 
 
@@ -1451,112 +1440,106 @@ main_window::handle_octave_ready ()
 #endif
     }
 
-  if (_start_gui)
-    focus_command_window ();  // make sure that the command window has focus
+  focus_command_window ();  // make sure that the command window has focus
 
 }
 
 
 void
-main_window::construct_octave_qt_link (void)
+main_window::connect_octave_qt_link (octave_qt_link *octqt_link)
 {
-  _octave_qt_link = new octave_qt_link (this);
-
-  connect (_octave_qt_link, SIGNAL (exit_app_signal (int)),
+
+  connect (octqt_link, SIGNAL (exit_app_signal (int)),
            this, SLOT (exit_app (int)));
 
-  connect (_octave_qt_link, SIGNAL (confirm_shutdown_signal ()),
+  connect (octqt_link, SIGNAL (confirm_shutdown_signal ()),
            this, SLOT (confirm_shutdown_octave ()));
 
-  if (_start_gui)
-    {
-      connect (_octave_qt_link,
-               SIGNAL (set_workspace_signal
-                       (bool, bool, const QString&, const QStringList&,
-                        const QStringList&, const QStringList&,
-                        const QStringList&, const QIntList&)),
-               _workspace_model,
-               SLOT (set_workspace
-                     (bool, bool, const QString&, const QStringList&,
-                      const QStringList&, const QStringList&,
-                      const QStringList&, const QIntList&)));
-
-      connect (_octave_qt_link, SIGNAL (clear_workspace_signal ()),
-               _workspace_model, SLOT (clear_workspace ()));
-
-      connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
-               this, SLOT (change_directory (QString)));
-      connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
-               file_browser_window, SLOT (update_octave_directory (QString)));
-      connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
-               editor_window, SLOT (update_octave_directory (QString)));
-
-      connect (_octave_qt_link,
-               SIGNAL (execute_command_in_terminal_signal (QString)),
-               this, SLOT (execute_command_in_terminal (QString)));
-
-      connect (_octave_qt_link,
-               SIGNAL (set_history_signal (const QStringList&)),
-               history_window, SLOT (set_history (const QStringList&)));
-
-      connect (_octave_qt_link,
-               SIGNAL (append_history_signal (const QString&)),
-               history_window, SLOT (append_history (const QString&)));
-
-      connect (_octave_qt_link,
-               SIGNAL (clear_history_signal (void)),
-               history_window, SLOT (clear_history (void)));
-
-      connect (_octave_qt_link, SIGNAL (enter_debugger_signal ()),
-               this, SLOT (handle_enter_debugger ()));
-
-      connect (_octave_qt_link, SIGNAL (exit_debugger_signal ()),
-               this, SLOT (handle_exit_debugger ()));
-
-      connect (_octave_qt_link,
-               SIGNAL (show_preferences_signal (void)),
-               this, SLOT (process_settings_dialog_request ()));
+  connect (octqt_link,
+           SIGNAL (set_workspace_signal
+                   (bool, bool, const QString&, const QStringList&,
+                    const QStringList&, const QStringList&,
+                    const QStringList&, const QIntList&)),
+           _workspace_model,
+           SLOT (set_workspace
+                 (bool, bool, const QString&, const QStringList&,
+                  const QStringList&, const QStringList&,
+                  const QStringList&, const QIntList&)));
+
+  connect (octqt_link, SIGNAL (clear_workspace_signal ()),
+           _workspace_model, SLOT (clear_workspace ()));
+
+  connect (octqt_link, SIGNAL (change_directory_signal (QString)),
+           this, SLOT (change_directory (QString)));
+  connect (octqt_link, SIGNAL (change_directory_signal (QString)),
+           file_browser_window, SLOT (update_octave_directory (QString)));
+  connect (octqt_link, SIGNAL (change_directory_signal (QString)),
+           editor_window, SLOT (update_octave_directory (QString)));
+
+  connect (octqt_link,
+           SIGNAL (execute_command_in_terminal_signal (QString)),
+           this, SLOT (execute_command_in_terminal (QString)));
+
+  connect (octqt_link,
+           SIGNAL (set_history_signal (const QStringList&)),
+           history_window, SLOT (set_history (const QStringList&)));
+
+  connect (octqt_link,
+           SIGNAL (append_history_signal (const QString&)),
+           history_window, SLOT (append_history (const QString&)));
+
+  connect (octqt_link,
+           SIGNAL (clear_history_signal (void)),
+           history_window, SLOT (clear_history (void)));
+
+  connect (octqt_link, SIGNAL (enter_debugger_signal ()),
+           this, SLOT (handle_enter_debugger ()));
+
+  connect (octqt_link, SIGNAL (exit_debugger_signal ()),
+           this, SLOT (handle_exit_debugger ()));
+
+  connect (octqt_link,
+           SIGNAL (show_preferences_signal (void)),
+           this, SLOT (process_settings_dialog_request ()));
 
 #ifdef HAVE_QSCINTILLA
-      connect (_octave_qt_link,
-               SIGNAL (edit_file_signal (const QString&)),
-               editor_window,
-               SLOT (handle_edit_file_request (const QString&)));
+  connect (octqt_link,
+           SIGNAL (edit_file_signal (const QString&)),
+           editor_window,
+           SLOT (handle_edit_file_request (const QString&)));
 #endif
 
-      connect (_octave_qt_link,
-               SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
-               this,
-               SLOT (handle_insert_debugger_pointer_request (const QString&, int)));
-
-      connect (_octave_qt_link,
-               SIGNAL (delete_debugger_pointer_signal (const QString&, int)),
-               this,
-               SLOT (handle_delete_debugger_pointer_request (const QString&, int)));
-
-      connect (_octave_qt_link,
-               SIGNAL (update_breakpoint_marker_signal (bool, const QString&, int)),
-               this,
-               SLOT (handle_update_breakpoint_marker_request (bool, const QString&,
-                                                              int)));
-
-      connect (_octave_qt_link,
-               SIGNAL (show_doc_signal (const QString &)),
-               this, SLOT (handle_show_doc (const QString &)));
-
-      connect (_workspace_model,
-               SIGNAL (rename_variable (const QString&, const QString&)),
-               this,
-               SLOT (handle_rename_variable_request (const QString&,
-                                                     const QString&)));
-
-      connect (command_window, SIGNAL (interrupt_signal (void)),
-               _octave_qt_link, SLOT (terminal_interrupt (void)));
-    }
-
-  _octave_qt_link->execute_interpreter ();
-
-  octave_link::connect_link (_octave_qt_link);
+  connect (octqt_link,
+           SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
+           this,
+           SLOT (handle_insert_debugger_pointer_request (const QString&, int)));
+
+  connect (octqt_link,
+           SIGNAL (delete_debugger_pointer_signal (const QString&, int)),
+           this,
+           SLOT (handle_delete_debugger_pointer_request (const QString&, int)));
+
+  connect (octqt_link,
+           SIGNAL (update_breakpoint_marker_signal (bool, const QString&, int)),
+           this,
+           SLOT (handle_update_breakpoint_marker_request (bool, const QString&,
+                                                          int)));
+
+  connect (octqt_link,
+           SIGNAL (show_doc_signal (const QString &)),
+           this, SLOT (handle_show_doc (const QString &)));
+
+  connect (_workspace_model,
+           SIGNAL (rename_variable (const QString&, const QString&)),
+           this,
+           SLOT (handle_rename_variable_request (const QString&,
+                                                 const QString&)));
+
+  connect (command_window, SIGNAL (interrupt_signal (void)),
+           octqt_link, SLOT (terminal_interrupt (void)));
+
+  connect (this, SIGNAL (shutdown_result (bool)),
+           octqt_link, SLOT (shutdown_confirmation (bool)));
 }
 
 void
diff --git a/libgui/src/main-window.h b/libgui/src/main-window.h
--- a/libgui/src/main-window.h
+++ b/libgui/src/main-window.h
@@ -75,7 +75,7 @@ public:
   typedef std::pair <std::string, std::string> name_pair;
   typedef std::pair <int, int> int_pair;
 
-  main_window (QWidget *parent = 0, bool start_gui = true);
+  main_window (QWidget *parent = 0, octave_qt_link *octqt_link = 0);
 
   ~main_window (void);
 
@@ -105,6 +105,8 @@ signals:
   void selectAll_signal (void);
   void undo_signal (void);
 
+  void shutdown_result (bool sd);
+
 public slots:
 
   void focus_changed (QWidget *w_old, QWidget *w_new);
@@ -226,7 +228,7 @@ private:
 
   void construct (void);
 
-  void construct_octave_qt_link (void);
+  void connect_octave_qt_link (octave_qt_link *octqt_link);
 
   QAction *add_action (QMenu *menu, const QIcon &icon, const QString &text,
                        const char *member, const QWidget *receiver = 0);
@@ -250,8 +252,6 @@ private:
 
   void construct_tool_bar (void);
 
-  void establish_octave_link (void);
-
   void save_workspace_callback (const std::string& file);
 
   void load_workspace_callback (const std::string& file);
@@ -390,8 +390,6 @@ private:
 
   QWidget * community_news_window;
 
-  octave_qt_link *_octave_qt_link;
-
   QClipboard *_clipboard;
 
   // Flag for closing whole application.
@@ -413,7 +411,6 @@ private:
 
   bool _prevent_readline_conflicts;
   bool _suppress_dbg_location;
-  bool _start_gui;
 };
 
 class news_reader : public QObject
diff --git a/libgui/src/octave-gui.cc b/libgui/src/octave-gui.cc
--- a/libgui/src/octave-gui.cc
+++ b/libgui/src/octave-gui.cc
@@ -122,6 +122,10 @@ octave_start_gui (int argc, char *argv[]
   QTextCodec::setCodecForCStrings (QTextCodec::codecForName ("UTF-8"));
 #endif
 
+  octave_qt_link oqt_link (0);
+  oqt_link.execute_interpreter ();
+  octave_link::connect_link (&oqt_link);
+
   if (start_gui)
     {
       // show wizard if this is the first run
@@ -172,16 +176,13 @@ octave_start_gui (int argc, char *argv[]
 
       // shortcut manager
       shortcut_manager::init_data ();
-    }
 
-  // Create and show main window.
+      // Create and show main window.
 
-  main_window w (0, start_gui);
+      main_window w (0, &oqt_link);
 
-  w.read_settings ();
+      w.read_settings ();
 
-  if (start_gui)
-    {
       w.init_terminal_size ();
 
       // Connect signals for changes in visibility not before w
@@ -190,9 +191,25 @@ octave_start_gui (int argc, char *argv[]
       w.connect_visibility_changed ();
 
       w.focus_command_window ();
+
+      return application.exec ();
     }
   else
-    application.setQuitOnLastWindowClosed (false);
+    {
+      application.setQuitOnLastWindowClosed (false);
 
-  return application.exec ();
+      // Since there is an active link, need a shutdown confirmation
+      // which needs a Qt object.  Feedback to self.
+      QObject::connect (&oqt_link, SIGNAL (confirm_shutdown_signal ()),
+                        &oqt_link, SLOT (feedback_shutdown ()));
+      QObject::connect (&oqt_link, SIGNAL (feedback_shutdown_result (bool)),
+                        &oqt_link, SLOT (shutdown_confirmation (bool)));
+
+      // Could connect directly to QApplication::quit() slot if not for
+      // the return code.
+      QObject::connect (&oqt_link, SIGNAL (exit_app_signal (int)),
+                        &oqt_link, SLOT (feedback_exit_app (int)));
+
+      return application.exec ();
+    }
 }
diff --git a/libgui/src/octave-qt-link.cc b/libgui/src/octave-qt-link.cc
--- a/libgui/src/octave-qt-link.cc
+++ b/libgui/src/octave-qt-link.cc
@@ -29,6 +29,7 @@ along with Octave; see the file COPYING.
 #include <QStringList>
 #include <QDialog>
 #include <QDir>
+#include <QApplication>
 
 #include "str-vec.h"
 #include "dialog.h"
@@ -573,3 +574,25 @@ octave_qt_link::terminal_interrupt (void
 {
   command_interpreter->interrupt ();
 }
+
+void
+octave_qt_link::shutdown_confirmation (bool sd)
+{
+  _shutdown_confirm_result = sd;
+
+  // Awake the worker thread so that it continues shutting down (or not).
+  waitcondition.wakeAll ();
+}
+
+void
+octave_qt_link::feedback_shutdown (void)
+{
+  emit feedback_shutdown_result (true);
+}
+
+void
+octave_qt_link::feedback_exit_app (int returnCode)
+{
+  qApp->exit (returnCode);
+}
+
diff --git a/libgui/src/octave-qt-link.h b/libgui/src/octave-qt-link.h
--- a/libgui/src/octave-qt-link.h
+++ b/libgui/src/octave-qt-link.h
@@ -135,7 +135,6 @@ public:
 
   QMutex mutex;
   QWaitCondition waitcondition;
-  void shutdown_confirmation (bool sd) {_shutdown_confirm_result = sd;}
 
 private:
 
@@ -194,9 +193,15 @@ signals:
   void confirm_shutdown_signal (void);
   void exit_app_signal (int status);
 
+  void feedback_shutdown_result (bool sd);
+
 public slots:
 
   void terminal_interrupt (void);
+  void shutdown_confirmation (bool sd);
+
+  void feedback_shutdown (void);
+  void feedback_exit_app (int returnCode);
 };
 
 #endif
exporting patch:
<fdopen>
