diff options
-rw-r--r-- | src/corelib/io/qtextstream.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp | 7 |
2 files changed, 10 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() #endif // convert from unicode to raw data - QByteArray data = codec->fromUnicode(writeBuffer.data(), 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.data(), writeBuffer.size(), &writeConverterState) + : writeBuffer.toLatin1(); #else QByteArray data = writeBuffer.toLocal8Bit(); #endif diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index c19e80bff3..2ae085cb0b 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -247,6 +247,13 @@ private: QString testFileName; }; +void runOnExit() +{ + QByteArray buffer; + QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << endl; +} +Q_DESTRUCTOR_FUNCTION(runOnExit) + tst_QTextStream::tst_QTextStream() : tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX") { |