Target setup page: Un-queue connection to kit manager

If we have a project with two enabled targets and we remove both of the
associated kits, one of the targets temporarily becomes the active one.
If the activeTargetChanged() signal gets queued, then the receiver will
be called with an invalid target pointer, as the target has been removed
in the meantime.
It is unclear why the signal was queued in the first place. Presumably
the original reasoning is no longer applicable after various
refactorings.
This amends (and effectively reverts) commit c13b20f160.

Task-number: QTCREATORBUG-23075
Change-Id: I3c63c763319734a4d52b3bb221919b20fd123dbe
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2019-10-21 09:43:21 +02:00
parent 1646c266d6
commit 6fd29da2cb

View File

@@ -674,7 +674,7 @@ TargetGroupItem::TargetGroupItem(const QString &displayName, Project *project)
QObject::connect(project, &Project::removedTarget, QObject::connect(project, &Project::removedTarget,
d.get(), &TargetGroupItemPrivate::handleTargetRemoved); d.get(), &TargetGroupItemPrivate::handleTargetRemoved);
QObject::connect(project, &Project::activeTargetChanged, QObject::connect(project, &Project::activeTargetChanged,
d.get(), &TargetGroupItemPrivate::handleTargetChanged, Qt::QueuedConnection); d.get(), &TargetGroupItemPrivate::handleTargetChanged);
} }
TargetGroupItem::~TargetGroupItem() = default; TargetGroupItem::~TargetGroupItem() = default;
@@ -748,8 +748,10 @@ TargetItem *TargetGroupItem::currentTargetItem() const
TargetItem *TargetGroupItem::targetItem(Target *target) const TargetItem *TargetGroupItem::targetItem(Target *target) const
{ {
if (target) if (target) {
return findFirstLevelChild([target](TargetItem *item) { return item->target() == target; }); Id needle = target->id(); // Unconfigured project have no active target.
return findFirstLevelChild([needle](TargetItem *item) { return item->m_kitId == needle; });
}
return nullptr; return nullptr;
} }