[Qt-interest] How to use ostream << operator with Qt?

K. Frank kfrank29.c at gmail.com
Fri May 14 23:00:02 CEST 2010


Hello All -

I sometimes write an ostream "<<" operator for my classes, primarily for
development and debugging purposes.

Is there a common (and easy and lightweight) idiom for using iostream-style
stuff to output diagnostic messages in Qt?

For example, I can output simple strings through qDebug(), but, because
qDebug returns a QDebug rather than a std::ostream, I face the nuisance
of having to implement a QDebug version of "<<".

(By the way, for those who are unaware, microsoft makes it a real PITA
to use cout / cerr with windows applications.)

Is there some slick way to use an ostream "<<" with Qt?  I was thinking
perhaps to somehow wrap a stringsteam around QDebug, but I don't have
in mind a clear scheme for doing so.

(Another thing I was thinking of was making widget that is an ostream
that I could drop onto my applications\'s gui to act as a log or debugging
window  Has anyone tried anything like this or have tips for doing so?)

Thanks in advance for any ideas.


K. Frank



More information about the Qt-interest-old mailing list