diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-03-15 00:07:37 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-03-17 17:14:36 +0100 |
commit | 5089db0303f4ee0ca0d7c6814e06beff119d8500 (patch) | |
tree | 90da6fe39d7502953431dac57e081727e0c3dbe7 /src/corelib/thread/qfuture_impl.h | |
parent | 440438092bc6276399cbb1bd9425227898221587 (diff) |
QFuture: fix QtFuture::connect corner-cases
Connecting to nullptr, or connecting to a non-signal PMF, would result
in a QFuture which would never finish. Catch these cases and handle
them.
Windows+MSVC for some reason fails the test. I can't entirely understand
why, so I've marked it as XFAIL, with QTBUG-101761 to track it.
Change-Id: I314980e7e9b7156d8cddd3b33d5cbf1d0bcd6116
Pick-to: 6.2 6.3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/corelib/thread/qfuture_impl.h')
-rw-r--r-- | src/corelib/thread/qfuture_impl.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 22f51d755b..4c68a527da 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -880,6 +880,11 @@ static QFuture<ArgsType<Signal>> connect(Sender *sender, Signal signal) using ArgsType = ArgsType<Signal>; QFutureInterface<ArgsType> promise; promise.reportStarted(); + if (!sender) { + promise.reportCanceled(); + promise.reportFinished(); + return promise.future(); + } using Connections = std::pair<QMetaObject::Connection, QMetaObject::Connection>; auto connections = std::make_shared<Connections>(); @@ -910,6 +915,12 @@ static QFuture<ArgsType<Signal>> connect(Sender *sender, Signal signal) }); } + if (!connections->first) { + promise.reportCanceled(); + promise.reportFinished(); + return promise.future(); + } + connections->second = QObject::connect(sender, &QObject::destroyed, sender, [promise, connections]() mutable { QObject::disconnect(connections->first); |