Hi @ademmler,
Just for inspiration, here's a class I use for capturing std::cout for verifying output in unit tests. You should be able to use it for std::err too, and then either qDebug() the captured text, or invoke your installed message handler directly, as @JonB suggested.
Note, though, this would only work for code that uses the std::cout and/or std::cerr C++ output streams, which is close but not quite the same as, for example, plain C code writing to the stdout or stderr file stream pointers, so it depends on how your included libraries, etc are writing their output.
/*!
* Implements a simple RAII capture of output streams.
*/
class OutputStreamCapture
{
public:
explicit OutputStreamCapture(std::ostream * const stream) : stream(stream)
{
originalBuffer = stream->rdbuf(newBuffer.rdbuf());
}
std::string data() const
{
return newBuffer.str();
}
~OutputStreamCapture()
{
stream->rdbuf(originalBuffer);
}
private:
std::ostringstream newBuffer;
std::streambuf * originalBuffer;
std::ostream * stream;
};
Use it like:
const OutputStreamCapture capture(&std::cout);
// do stuff that might output to std::cout.
qDebug() << capture.data();
Again, this won't capture non-C++ streams, but at least it is portable (on Linux, macOS and Windows at least).
Hope that helps.
Cheers.