DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
qdebugstream.hpp
Go to the documentation of this file.
1#ifndef QDEBUGSTREAM_H_
2#define QDEBUGSTREAM_H_
3
4#include <iostream>
5#include <streambuf>
6#include <string>
7#include "ers/ers.hpp"
8#include <QTextEdit>
9#include <QMutexLocker>
10#include <QMutex>
11#include <QEvent>
12#include <QCoreApplication>
13namespace daq {
14namespace QTUtils {
15
27class QDebugStream: public QObject, public std::basic_streambuf<char> {
28 Q_OBJECT
29public:
30
33 QDebugStream(std::ostream &stream, QTextEdit* text_edit) :
34 m_stream(stream) {
35 m_mutex = new QMutex();
36 log_window = text_edit;
37 m_old_buf = stream.rdbuf();
38 stream.rdbuf(this);
39 }
41 // output anything that is left
42 if (!m_string.empty())
43 log_window->append(m_string.c_str());
44
45 m_stream.rdbuf(m_old_buf);
46 delete m_mutex;
47 }
48
49protected:
50 virtual int_type overflow(int_type v);
51 virtual std::streamsize xsputn(const char *p, std::streamsize n);
52 virtual bool event(QEvent* event);
53private:
54 std::ostream &m_stream;
55 std::streambuf *m_old_buf;
56 std::string m_string;
57 QTextEdit* log_window;
58 QMutex *m_mutex;
59 QString m_text;
60};
61}
62}
63#endif /*QTEXTEDIT_H_*/
virtual bool event(QEvent *event)
virtual std::streamsize xsputn(const char *p, std::streamsize n)
QDebugStream(std::ostream &stream, QTextEdit *text_edit)
virtual int_type overflow(int_type v)
Including ers headers.