summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-07-12 19:49:54 +0200
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2021-07-27 16:16:13 +0000
commit62b33b6730ab995022149e65618a4a92b4992a49 (patch)
treeab4fc07906043c46a861a687bdec5baa7ebb2477
parent0c8b98774cd0f3dad939d31e820e7e47c1da088a (diff)
QTextStream: Always use direct connection inside QDeviceClosedNotifier
Force direct connection when connecting aboutToClose() signal of device to flushStream() slot of QDeviceClosedNotifier. This allows use of a QTextStream from multiple threads when synchronization is handled by the application. Queued connections from aboutToClose() don't make much sense because the device is closed immediately after emitting the signal. If a QTextStream object is used by threads different from the one where it was created, queued connection may result in attempting to flush the data after the associated device is already closed, and accessing the QTextStream's buffers from multiple threads. Fixes: QTBUG-12055 Change-Id: If601d0f04f08b248b21ed1630b7dfd3546aee068 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/serialization/qtextstream_p.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/serialization/qtextstream_p.h b/src/corelib/serialization/qtextstream_p.h
index 7d6889aa70..79643de35d 100644
--- a/src/corelib/serialization/qtextstream_p.h
+++ b/src/corelib/serialization/qtextstream_p.h
@@ -70,8 +70,13 @@ public:
inline void setupDevice(QTextStream *stream, QIODevice *device)
{
disconnect();
- if (device)
- connect(device, SIGNAL(aboutToClose()), this, SLOT(flushStream()));
+ if (device) {
+ // Force direct connection here so that QTextStream can be used
+ // from multiple threads when the application code is handling
+ // synchronization (see also QTBUG-12055).
+ connect(device, SIGNAL(aboutToClose()), this, SLOT(flushStream()),
+ Qt::DirectConnection);
+ }
this->stream = stream;
}