[Interest] QDateTime + QXmlStreamWriter on non-UTF8 compatible systems

Scott Bloom scott at towel42.com
Tue Dec 26 13:01:58 CET 2017


> What would you have it write?
> ====
> If I set the encoding, I would expect it to use that encoding.  It doesn't. 
> When using QString, all encoding settings are ignored.  That to me is 
> a problem, at a minimum it should be documented as the expected and 
> correct behavior.

Because you're writing to QString, which means it's UTF-16. The codec is *not* used when using a QString, for obvious reasons.

> If I set the encoding to "UTF-8" and the target is a QString, it 
> should encode to UTF-8 in the QString.

Will never happen. If yuo want to use UTF-8, use QByteArray, not QString.
=========
I understand we will never agree on this.  And that’s find, but Ill just close with this.

When someone who has been an active user of Qt for 15+ years, says there is something fundamentally missing from the documentation.  That caused a critical bug (per his customers definition) in their tool was created because core functionality is undocumented, where the only fix needed from Qt is a simple documentation fix.  Maybe, just maybe, take into consideration that if that person has the confusion others might as well.

I agree, knowing what I now know, that using a QString as the target for QXmlStreamWriter was the wrong choice, and QByteArray should have been chosen.  I really do.. My point is, without inspecting the Qt code, there is absolutely no way to know this.  Zero. Zilch.  Based on the documentation, when you set an codec the codec it should be used for encoding any data that is written.. 

In fact, as I said before, the documentation explicitly says that.  

void QXmlStreamWriter::​setCodec(QTextCodec * codec)
Sets the codec for this stream to codec. The codec is used for encoding any data that is written. By default, QXmlStreamWriter uses UTF-8.

The encoding information is stored in the initial xml tag which gets written when you call writeStartDocument(). Call this function before calling writeStartDocument().


If the documentation said: Note, when using a QString as a target, the codec setting is ignored.  Since QString is always UTF-16.

Then I would never had asked any question to the mailing list.

Scott


More information about the Interest mailing list