[Qt-interest] How to use ostream << operator with Qt?
K. Frank
kfrank29.c at gmail.com
Sat May 15 03:30:45 CEST 2010
Hello Mark -
On Fri, May 14, 2010 at 7:30 PM, K. Frank <kfrank29.c at gmail.com> wrote:
> ...
> 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
> ...
>> 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.
Well, now I've tried it, and it seems to be just what the doctor ordered.
I have used it with a class for which I've implemented
std::ostream& operator<<
and everything seems to work as expected.
A couple of minor comments:
g++ complains with an (easily fixed) signed/unsigned comparison warning.
qdebug.h doesn't respect std::flush (not that there's anything in the
code that suggests it would).
I haven't tried qdebug.h with any third-party libraries that write to
cout or cerr, but by all appearances, qdebug.h will successfully
capture that output without any need to modify the third-party code.
Not the fault of qdebug.h (Rather, it's the fault of QDebug.), but the lines
written to qdebug are all separated by blank lines (at least when the
output passes through gdb running from a command prompt).
Also (this is a pure QDebug question): Why, when I use QDebug to
output messages (e.g., qDebug ("a message");) are the messages
prefaced with "warning: ", rather than something like "debug: " or
"info: " (or maybe even nothing)?
Thanks again to Mark for the pointer.
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