changeset 17918:a38cee8f0a9b

derive octave_main_thread from QObject, not QThread * main-window.h, main-window.cc (main_window::_octave_main_thread): Delete member variable and all uses. * libgu/src/module.mk (octave_gui_MOC): Include src/moc-octave-main-thread.cc in the list. * octave-main-thread.h, octave-main-thread.cc (octave_main_thread::run): Delete. (octave_main_thread::execute): Rename from octave_main_thread::run. (class octave_main_thread): Derive from QObject, not QThread. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::octave_interpreter): New member variable. (octave_qt_link::main_thread): Now a pointer to a QThread object. (octave_qt_link::execute_interpreter_signal): New signal. (octave_qt_link::octave_qt_link): Create thread and octave_interpreter object here instead of accepting thread as argument. Move octave_interpreter to the main_thread object and connect the execute_interpreter signal to the corresponding slot.
author John W. Eaton <jwe@octave.org>
date Tue, 12 Nov 2013 12:36:30 -0500
parents c9f622fd7307
children b6d07dd90f3d
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk libgui/src/octave-main-thread.cc libgui/src/octave-main-thread.h libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h
diffstat 7 files changed, 34 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/main-window.cc	Tue Nov 12 12:36:30 2013 -0500
@@ -79,7 +79,6 @@
     workspace_window (new workspace_view (this)),
     find_files_dlg (0),
     release_notes_window (0),
-    _octave_main_thread (0),
     _octave_qt_link (0),
     _clipboard (QApplication::clipboard ()),
     _cmd_queue (new QStringList ()),  // no command pending
@@ -114,7 +113,6 @@
       delete release_notes_window;
       release_notes_window = 0;
     }
-  delete _octave_main_thread;
   delete _octave_qt_link;
   delete _cmd_queue;
 }
@@ -1001,9 +999,7 @@
 void
 main_window::construct_octave_qt_link (void)
 {
-  _octave_main_thread = new octave_main_thread ();
-
-  _octave_qt_link = new octave_qt_link (_octave_main_thread);
+  _octave_qt_link = new octave_qt_link ();
 
   connect (_octave_qt_link, SIGNAL (exit_signal (int)),
            this, SLOT (exit (int)));
--- a/libgui/src/main-window.h	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/main-window.h	Tue Nov 12 12:36:30 2013 -0500
@@ -327,8 +327,6 @@
   // release notes window
   QWidget * release_notes_window;
 
-  octave_main_thread *_octave_main_thread;
-
   octave_qt_link *_octave_qt_link;
 
   QClipboard *_clipboard;
--- a/libgui/src/module.mk	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/module.mk	Tue Nov 12 12:36:30 2013 -0500
@@ -90,6 +90,7 @@
   src/moc-files-dock-widget.cc \
   src/moc-history-dock-widget.cc \
   src/moc-main-window.cc \
+  src/moc-octave-main-thread.cc \
   src/moc-octave-qt-link.cc \
   src/moc-settings-dialog.cc \
   src/moc-news-dock-widget.cc \
--- a/libgui/src/octave-main-thread.cc	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/octave-main-thread.cc	Tue Nov 12 12:36:30 2013 -0500
@@ -36,16 +36,10 @@
 #include "octave-link.h"
 
 void
-octave_main_thread::run (void)
+octave_main_thread::execute_interpreter (void)
 {
   octave_initialize_interpreter (octave_cmdline_argc, octave_cmdline_argv,
                                  octave_embedded);
 
   octave_execute_interpreter ();
 }
-
-void
-octave_main_thread::execute_interpreter (void)
-{
-  start ();
-}
--- a/libgui/src/octave-main-thread.h	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/octave-main-thread.h	Tue Nov 12 12:36:30 2013 -0500
@@ -24,26 +24,29 @@
 #ifndef OCTAVEMAINTHREAD_H
 #define OCTAVEMAINTHREAD_H
 
-#include <QThread>
+#include <QObject>
 
 /**
   * \class octave_main
   * \brief This class represents a thread just running octave_main.
   * \author Jacob Dawid
   */
-class octave_main_thread : public QThread
+class octave_main_thread : public QObject
 {
+  Q_OBJECT
+
 public:
+
   // Create a new thread for running the octave interpreter.
-  octave_main_thread (void) : QThread () { }
+
+  octave_main_thread (void) : QObject () { }
+
+public slots:
 
   // Start the thread and initialize and execute the octave
   // interpreter.
+
   void execute_interpreter (void);
-
-protected:
-  // Avoid exec.  Run the octave interpreter in the new thread.
-  void run (void);
 };
 
 #endif // OCTAVEMAINTHREAD_H
--- a/libgui/src/octave-qt-link.cc	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/octave-qt-link.cc	Tue Nov 12 12:36:30 2013 -0500
@@ -43,16 +43,24 @@
 
 #include "resource-manager.h"
 
-octave_qt_link::octave_qt_link (octave_main_thread *mt)
-  : octave_link (), main_thread (mt)
-{ }
+octave_qt_link::octave_qt_link (void)
+  : octave_link (), main_thread (new QThread ()),
+    octave_interpreter (new octave_main_thread ())
+{
+  connect (this, SIGNAL (execute_interpreter_signal (void)),
+           octave_interpreter, SLOT (execute_interpreter (void)));
+
+  octave_interpreter->moveToThread (main_thread);
+
+  main_thread->start ();
+}
 
 octave_qt_link::~octave_qt_link (void) { }
 
 void
 octave_qt_link::execute_interpreter (void)
 {
-  main_thread->execute_interpreter ();
+  emit execute_interpreter_signal ();
 }
 
 bool
--- a/libgui/src/octave-qt-link.h	Wed Nov 13 06:36:50 2013 +0000
+++ b/libgui/src/octave-qt-link.h	Tue Nov 12 12:36:30 2013 -0500
@@ -31,6 +31,7 @@
 #include <QList>
 #include <QObject>
 #include <QString>
+#include <QThread>
 
 #include "octave-link.h"
 #include "octave-main-thread.h"
@@ -52,7 +53,7 @@
 
 public:
 
-  octave_qt_link (octave_main_thread *mt);
+  octave_qt_link (void);
 
   ~octave_qt_link (void);
 
@@ -128,6 +129,7 @@
   void do_show_preferences (void);
 
   void do_show_doc (const std::string& file);
+
 private:
 
   // No copying!
@@ -140,10 +142,15 @@
   void do_delete_debugger_pointer (const std::string& file, int line);
 
   // Thread running octave_main.
-  octave_main_thread *main_thread;
+  QThread *main_thread;
+
+  // Octave interpreter (misnamed class)
+  octave_main_thread *octave_interpreter;
 
 signals:
 
+  void execute_interpreter_signal (void);
+
   void exit_signal (int status);
 
   void edit_file_signal (const QString& file);