also catches cerr now

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@134 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d 2013-01-15 17:11:54 +00:00
parent ac79bb86fb
commit 6a3747638d
3 changed files with 26 additions and 40 deletions

View File

@ -15,7 +15,6 @@
#include <QApplication> #include <QApplication>
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include <QEvent>
#include <QCustomEvent> #include <QCustomEvent>
#include <iostream> #include <iostream>
@ -30,9 +29,9 @@ using namespace std;
class qStreamEvent:public QEvent{ class qStreamEvent:public QEvent{
public: public:
qStreamEvent(QString s):QEvent(static_cast<QEvent::Type>(STREAMEVENT)) {str=s;}; qStreamEvent(QString s):QEvent(static_cast<QEvent::Type>(STREAMEVENT)),str(s){}
/** \returns the progress index */ /** \returns the progress index */
QString getString() {return str;}; QString getString() {return str;}
private: private:
QString str; QString str;
@ -43,27 +42,18 @@ private:
class qDebugStream : public basic_streambuf<char> { class qDebugStream : public basic_streambuf<char> {
public: public:
qDebugStream(ostream &stream, ostream &estream, QWidget* w) : m_stream(stream), e_stream(estream), log_window(w) { qDebugStream(ostream &stream, QWidget* w) : m_stream(stream), log_window(w) {
m_old_buf = stream.rdbuf(); m_old_buf = stream.rdbuf();
stream.rdbuf(this); stream.rdbuf(this);
//e_old_buf = stream.rdbuf(); }
//estream.rdbuf(this);
};
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
~qDebugStream(){ ~qDebugStream(){
// output anything that is left // output anything that is left
if (!m_string.empty()) { if (!m_string.empty())
qStreamEvent *ce=new qStreamEvent(m_string.c_str()); QApplication::postEvent(log_window, new qStreamEvent(m_string.c_str()));
QApplication::postEvent(log_window, ce);
#ifdef VERBOSE
cerr << m_string << endl;
#endif
}
m_stream.rdbuf(m_old_buf); m_stream.rdbuf(m_old_buf);
e_stream.rdbuf(e_old_buf);
} }
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
@ -71,11 +61,7 @@ public:
protected: protected:
virtual int_type overflow(int_type v){ virtual int_type overflow(int_type v){
if (v == '\n'){ if (v == '\n'){
qStreamEvent *ce=new qStreamEvent(m_string.c_str()); QApplication::postEvent(log_window, new qStreamEvent(m_string.c_str()));
QApplication::postEvent(log_window, ce);
#ifdef VERBOSE
cerr << m_string << endl;
#endif
m_string.erase(m_string.begin(), m_string.end()); m_string.erase(m_string.begin(), m_string.end());
} }
else else
@ -90,17 +76,11 @@ protected:
//changed from uint because of 64 bit //changed from uint because of 64 bit
int pos = 0; int pos = 0;
while (pos != string::npos) while (pos != string::npos){
{
pos = m_string.find('\n'); pos = m_string.find('\n');
if (pos != string::npos) if (pos != string::npos){
{
string tmp(m_string.begin(), m_string.begin() + pos); string tmp(m_string.begin(), m_string.begin() + pos);
qStreamEvent *ce=new qStreamEvent(tmp.c_str()); QApplication::postEvent(log_window, new qStreamEvent(tmp.c_str()));
QApplication::postEvent(log_window, ce);
#ifdef VERBOSE
cerr << tmp << endl;
#endif
m_string.erase(m_string.begin(), m_string.begin() + pos + 1); m_string.erase(m_string.begin(), m_string.begin() + pos + 1);
} }
} }
@ -112,8 +92,6 @@ protected:
private: private:
ostream &m_stream; ostream &m_stream;
streambuf *m_old_buf; streambuf *m_old_buf;
ostream &e_stream;
streambuf *e_old_buf;
string m_string; string m_string;
QWidget* log_window; QWidget* log_window;
}; };

View File

@ -55,7 +55,7 @@ private:
/** This class creates the log */ /** This class creates the log */
qDebugStream *qout; qDebugStream *qout;
//qDebugStream *qerr; qDebugStream *qerr;
/** methods */ /** methods */
/** Sets up the widget */ /** Sets up the widget */

View File

@ -24,7 +24,7 @@ using namespace std;
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
qTabMessages::qTabMessages(QWidget *parent,multiSlsDetector* detector):QWidget(parent),qout(0){//myDet(detector), qTabMessages::qTabMessages(QWidget *parent,multiSlsDetector* detector):QWidget(parent),qout(0),qerr(0){//myDet(detector),
myDet=detector; myDet=detector;
SetupWidgetWindow(); SetupWidgetWindow();
Initialization(); Initialization();
@ -36,6 +36,7 @@ qTabMessages::~qTabMessages(){
// delete myDet; // delete myDet;
delete dispLog; delete dispLog;
delete qout; delete qout;
delete qerr;
} }
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
@ -65,11 +66,9 @@ void qTabMessages::SetupWidgetWindow(){
gridLayout->addItem(new QSpacerItem(15,10,QSizePolicy::Fixed,QSizePolicy::Fixed),2,0); gridLayout->addItem(new QSpacerItem(15,10,QSizePolicy::Fixed,QSizePolicy::Fixed),2,0);
gridLayout->addWidget(dispLog,3,0,1,5); gridLayout->addWidget(dispLog,3,0,1,5);
qout=new qDebugStream(cout,cerr, this); qout=new qDebugStream(std::cout,this);
//qerr=new qDebugStream(cerr,this); qerr=new qDebugStream(std::cerr,this);
//qerr=NULL;
//qerr=new qDebugStream(std::cerr,this);cout<<"worked!"<<endl;
} }
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
@ -82,8 +81,17 @@ void qTabMessages::Initialization(){
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMessages::customEvent(QEvent *e) { void qTabMessages::customEvent(QEvent *e) {
if (e->type() == STREAMEVENT) if (e->type() == (STREAMEVENT)){
dispLog->append(((qStreamEvent*)e)->getString()); QString temp = ((qStreamEvent*)e)->getString();
dispLog->append(temp);
string t=string(temp.toAscii().constData());
if(t.find("not connect")!=string::npos)
qDefs::Message(qDefs::WARNING,string("Caught following message:\n\n")+t,"Messages");
else if(t.find("ould not")!=string::npos)
qDefs::Message(qDefs::WARNING,string("Caught following message:\n\n")+t,"Messages");
// dispLog->append(((qStreamEvent*)e)->getString());
}
} }
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------