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

K. Frank kfrank29.c at gmail.com
Sat May 15 01:30:09 CEST 2010


Mark -

Thank you.

On Fri, May 14, 2010 at 5:42 PM, Mark Long <mlong at weatherdata.com> wrote:
> You might take a look at this:
>
> http://www.qtforum.org/article/678/redirecting-cout-cerr-to-qdebug.html

At first glance, this looks quite good (certainly better than
something I'd write).

> I've had this link in my "check this out sometime" pile for a while now, but
> haven't had time to evaluate it yet.

I haven't actually tried it yet, but I'll give it a whirl, and report back.

By the way, I did something vaguely similar to this for windows.  I built an
ostream object that wrote to the console for console applications, and
wrote to an explicitly created console window for windows gui applications.
(This was back in the strstream days.)  One weakness of my hack is that
I would shlurk the entirety of _large_ objects into a strstream before flushing
any of it out to the console, causing my scheme a certain amount of grief.
I notice that "stele" (the qdebug.h poster) has avoided this mistake.

Thanks for the tip.  I'll be back...


K. Frank


> -Mark
>
> On 05/14/2010 04:00 PM, K. Frank wrote:
>>
>> 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?
>> ...
>> 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.
>> ...




More information about the Qt-interest-old mailing list