On Sun, Sep 13, 2009 at 12:53:54AM +0200, Vincent van Ravesteijn wrote: > It's slightly better in release mode. Now it only crashes when closing > the pipes, or quitting the monitor.
Is it any better with the attached patch (even in debug mode)? -- Enrico
Index: development/lyxserver/server_monitor.h =================================================================== --- development/lyxserver/server_monitor.h (revision 31378) +++ development/lyxserver/server_monitor.h (working copy) @@ -58,6 +58,8 @@ public Q_SLOTS: void openPipes(); void closePipes(); void submitCommand(); + void showInfo(QString const &); + void showNotice(QString const &); private: void createCmdsGroupBox(); @@ -87,4 +89,28 @@ private: ReadPipe * pipethread; }; + +class ReadPipe : public QThread +{ + Q_OBJECT + +public: + /// + ReadPipe(LyXServerMonitor * monitor) : lyxmonitor(monitor) {} + /// + void run() { lyxmonitor->readPipe(); } + /// + void emitInfo(QString const & msg) { emit info(msg); } + /// + void emitNotice(QString const & msg) { emit notice(msg); } + +signals: + void info(QString const &); + void notice(QString const &); + +private: + /// + LyXServerMonitor * lyxmonitor; +}; + #endif Index: development/lyxserver/server_monitor.cpp =================================================================== --- development/lyxserver/server_monitor.cpp (revision 31380) +++ development/lyxserver/server_monitor.cpp (working copy) @@ -44,34 +44,6 @@ #include "server_monitor.h" -class ReadPipe : public QThread { -public: - /// - ReadPipe(LyXServerMonitor * monitor) : lyxmonitor(monitor) {} - /// - void run() { lyxmonitor->readPipe(); } - -private: - /// - LyXServerMonitor * lyxmonitor; -}; - - -class DeleteThread : public QEvent { -public: - /// - DeleteThread(ReadPipe * thread) - : QEvent(QEvent::User), pipethread(thread) - {} - /// - ReadPipe * pipeThread() const { return pipethread; } - -private: - /// - ReadPipe * pipethread; -}; - - LyXServerMonitor::LyXServerMonitor() : pipein(-1), pipeout(-1), thread_exit(false), lyx_listen(false) { @@ -190,8 +162,7 @@ void LyXServerMonitor::readPipe() if (fromLyX.contains("bye")) { qWarning() << "monitor: LyX has closed " "connection!"; - infoLB->clear(); - notifyLB->setText(fromLyX); + pipethread->emitNotice(fromLyX); notified = true; break; } @@ -202,13 +173,10 @@ void LyXServerMonitor::readPipe() submitCommandPB->setDisabled(false); } } - if (fromLyX[0] == QLatin1Char('I')) { - infoLB->setText(fromLyX); - notifyLB->clear(); - } else { - infoLB->clear(); - notifyLB->setText(fromLyX); - } + if (fromLyX[0] == QLatin1Char('I')) + pipethread->emitInfo(fromLyX); + else + pipethread->emitNotice(fromLyX); #ifdef _WIN32 // On Windows, we have to close and reopen // the pipe after each use. @@ -218,9 +186,8 @@ void LyXServerMonitor::readPipe() O_RDONLY); if (pipeout < 0) { perror("monitor"); - infoLB->clear(); - notifyLB->setText("An error occurred, " - "closing pipes"); + pipethread->emitNotice("An error occurred, " + "closing pipes"); notified = true; break; } @@ -241,8 +208,7 @@ void LyXServerMonitor::readPipe() } #endif perror("monitor"); - infoLB->clear(); - notifyLB->setText("An error occurred, closing pipes"); + pipethread->emitNotice("An error occurred, closing pipes"); notified = true; break; } else @@ -252,16 +218,14 @@ void LyXServerMonitor::readPipe() if (!notified) { if (thread_exit) { qWarning() << "monitor: Closing pipes"; - infoLB->clear(); - notifyLB->setText("Closing pipes"); + pipethread->emitNotice("Closing pipes"); } else { qWarning() << "monitor: LyX has closed connection!"; - infoLB->clear(); - notifyLB->setText("LyX has closed connection!"); + pipethread->emitNotice("LyX has closed connection!"); } } - DeleteThread * event = new DeleteThread(pipethread); - QCoreApplication::postEvent(this, static_cast<QEvent *>(event)); + QEvent * event = new QEvent(QEvent::User); + QCoreApplication::postEvent(this, event); lyx_listen = false; closePipes(); } @@ -270,17 +234,29 @@ void LyXServerMonitor::readPipe() bool LyXServerMonitor::event(QEvent * e) { if (e->type() == QEvent::User) { - ReadPipe * pipeThread = - static_cast<DeleteThread *>(e)->pipeThread(); - pipeThread->wait(); + pipethread->wait(); thread_exit = false; - delete pipeThread; + delete pipethread; return true; } return QDialog::event(e); } +void LyXServerMonitor::showInfo(QString const & msg) +{ + infoLB->setText(msg); + notifyLB->clear(); +} + + +void LyXServerMonitor::showNotice(QString const & msg) +{ + infoLB->clear(); + notifyLB->setText(msg); +} + + void LyXServerMonitor::openPipes() { if (pipein == -1) { @@ -307,6 +283,10 @@ void LyXServerMonitor::openPipes() closePipes(); return; } + connect(pipethread, SIGNAL(info(QString const &)), + this, SLOT(showInfo(QString const &))); + connect(pipethread, SIGNAL(notice(QString const &)), + this, SLOT(showNotice(QString const &))); openPipesPB->setDisabled(true); closePipesPB->setDisabled(false); // greet LyX