changeset 18603:90dbbafb0502 stable

prevent X11 errors from appearing in GUI command window * octave-gui.cc (fdstderr): New file scope variable. (octave_start_gui): Dup stderr. (message_handler): Use fdstderr for messages.
author John W. Eaton <jwe@octave.org>
date Tue, 18 Mar 2014 12:19:18 -0400
parents c08776badd3d
children 2f39b386d399
files libgui/src/octave-gui.cc
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/octave-gui.cc	Mon Mar 17 18:35:54 2014 -0400
+++ b/libgui/src/octave-gui.cc	Tue Mar 18 12:19:18 2014 -0400
@@ -85,28 +85,37 @@
   int m_result;
 };
 
+#if ! defined (__WIN32__) || defined (__CYGWIN__)
+static int fdstderr = -1;
+#endif
 
 // Custom message handler for filtering some messages from Qt.
 
-void message_handler (QtMsgType type, const char *msg)
+void
+message_handler (QtMsgType type, const char *msg)
 {
+#if ! defined (__WIN32__) || defined (__CYGWIN__)
+  static FILE *errstream = fdopen (fdstderr, "a+");
+#else
+  static FILE *errstream = stderr;
+#endif
+
   switch (type)
     {
     case QtDebugMsg:
-      if (strncmp (msg, "QFileSystemWatcher: skipping native engine",42) != 0)
-        std::cerr << "Debug: " << msg << std::endl;
+      gnulib::fprintf (errstream, "Debug: %s\n", msg);
       break;
 
     case QtWarningMsg:
-      std::cerr << "Warning: " << msg << std::endl;
+      gnulib::fprintf (errstream, "Warning: %s\n", msg);
       break;
 
     case QtCriticalMsg:
-      std::cerr << "Critical: " << msg << std::endl;
+      gnulib::fprintf (errstream, "Critical: %s\n", msg);
       break;
 
     case QtFatalMsg:
-      std::cerr << "Fatal: " << msg << std::endl;
+      gnulib::fprintf (errstream, "Fatal: %s\n", msg);
       abort ();
 
     default:
@@ -122,6 +131,13 @@
 {
   octave_thread_manager::block_interrupt_signal ();
 
+#if ! defined (__WIN32__) || defined (__CYGWIN__)
+  // Store the file descriptor associated with the STDERR stream.  Send
+  // Qt messages there instead of to the STDERR stream that will be
+  // associated with the GUI command window.
+  fdstderr = gnulib::dup (STDERR_FILENO);
+#endif
+
   qInstallMsgHandler (message_handler);
 
   if (start_gui)