[Development] RFC: [Logging] Add quote(), noquote() stream modifiers to QDebug

Sebastian Lehmann qt at leemes.de
Fri Feb 28 14:29:05 CET 2014


Quoting Koehne Kai <Kai.Koehne at digia.com>:

>> -----Original Message-----
>> From: development-bounces+kai.koehne=digia.com at qt-project.org
>>
>> [...]
>> Of course, this feature should be disabled per default for compatibility
>> reasons, unless you say we don't have guarantees for the actual format of
>> qDebug output (I mean, it's for debugging, isn't it?); in this case  
>>  I'd even say
>> that escaping should be enabled per default, leading to less confusion /
>> frustration.
>
> I doubt any sane application on the assumption how QDebug formats   
> QByteArray's with 0's in it :)

Well, I thought about not only escaping the null char but also other  
non-printable chars and maybe even the double quote char. Ideally, the  
output is a valid C string literal (ideal in my opinion at least).

This can be discussed for QBA and QString separately. Typically you  
don't have null chars in a QString and _most_ strings only contain  
printable chars (except '\n'), yet when you debug them (again, that's  
what qDebug & friends are about), you want to see the raw content and  
see differences between encodings of the same (looking) text. This has  
already been discussed in the mailing list recently, but I've lost the  
overview.

Summarizing, I'd find it very useful if we can modify the behavior of  
qDebug to the needs of the developer. There are different scenarios in  
which s/he wants to debug strings differently. I know, converting  
QString to QBA makes sense if you want to take a deep look into the  
raw content, but that also requires some knowledge of UTF encoding  
(and requires null chars of QBA to not truncate the output). Maybe  
even some Qt::EscapeFooBar flags make sense, e.g. Qt::EscapeNull,  
Qt::EscapeNonPrintable, Qt::EscapeCString, etc., and .noescape() ==  
.escape(Qt::EscapeNothing)

> So yeah, let's just fix it. Can you create a bug report, so it's not  
>  forgotten?

I'll write a bug report around the weekend.

Regards,

Sebastian



More information about the Development mailing list