path: root/src
diff options
authorThiago Macieira <>2014-04-14 15:31:06 -0700
committerThe Qt Project <>2014-05-11 05:13:49 +0200
commitf2a40fa07123748ece2fc93790345379f15ef07f (patch)
treebb157bbcc3fd5113cf238b80b4e38f185793b80c /src
parentec8102166449b9b323948c0a8f5fabfa38705139 (diff)
Don't assume QLocale::codecForLocale always returns non-null
It may return null during program exit, due to QCoreGlobalData global static already having been destroyed. If that's the case, QTextStream needs to fall back to Latin 1, like QString::toLocal8Bit and fromLocal8Bit already do. Task-number: QTBUG-38316 Change-Id: I5949c8dec15b60f4a13b5d9307ed6abfc799fe20 Reviewed-by: Olivier Goffart <>
Diffstat (limited to 'src')
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index 163b087436..288a939ab2 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -569,7 +569,9 @@ void QTextStreamPrivate::flushWriteBuffer()
// convert from unicode to raw data
- QByteArray data = codec->fromUnicode(, writeBuffer.size(), &writeConverterState);
+ // codec might be null if we're already inside global destructors (QTestCodec::codecForLocale returned null)
+ QByteArray data = Q_LIKELY(codec) ? codec->fromUnicode(, writeBuffer.size(), &writeConverterState)
+ : writeBuffer.toLatin1();
QByteArray data = writeBuffer.toLocal8Bit();