Quantcast
Channel: How does QDebug()
Viewing all articles
Browse latest Browse all 5

Answer by Evan Teran for How does QDebug()

$
0
0

Something like this will do:

struct debug {
    debug() {
    }

    ~debug() {
        std::cerr << m_SS.str() << std::endl;
    }

public:
    // accepts just about anything
    template<class T>
    debug &operator<<(const T &x) {
        m_SS << x;
        return *this;
    }
private:
    std::ostringstream m_SS;
};

Which should let you do things like this:

debug() << "hello world";

I've used a pattern like this combined with a lock to provide a stream like logging system which can guarantee that log entries are written atomically.

NOTE: untested code, but should work :-)


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>