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 "ers/ers.hpp"
5#include <QCoreApplication>
6#include <QEvent>
7#include <QMutex>
8#include <QMutexLocker>
9#include <QTextEdit>
10#include <iostream>
11#include <streambuf>
12#include <string>
13namespace daq {
14namespace QTUtils {
15
28 : public QObject
29 , public std::basic_streambuf<char>
30{
31 Q_OBJECT
32public:
35 QDebugStream(std::ostream& stream, QTextEdit* text_edit)
36 : m_stream(stream)
37 {
38 m_mutex = new QMutex();
39 log_window = text_edit;
40 m_old_buf = stream.rdbuf();
41 stream.rdbuf(this);
42 }
44 {
45 // output anything that is left
46 if (!m_string.empty())
47 log_window->append(m_string.c_str());
48
49 m_stream.rdbuf(m_old_buf);
50 delete m_mutex;
51 }
52
53protected:
54 virtual int_type overflow(int_type v);
55 virtual std::streamsize xsputn(const char* p, std::streamsize n);
56 virtual bool event(QEvent* event);
57
58private:
59 std::ostream& m_stream;
60 std::streambuf* m_old_buf;
61 std::string m_string;
62 QTextEdit* log_window;
63 QMutex* m_mutex;
64 QString m_text;
65};
66}
67}
68#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.