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>
This commit is contained in:
parent
0c8b98774c
commit
62b33b6730
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user