diff --git a/src/plugins/projectexplorer/targetsettingspanel.cpp b/src/plugins/projectexplorer/targetsettingspanel.cpp index 98522e228ca7cf59ab53e08868769f7489320eed..55d12c586924447a18b146dd737620bae7c820b1 100644 --- a/src/plugins/projectexplorer/targetsettingspanel.cpp +++ b/src/plugins/projectexplorer/targetsettingspanel.cpp @@ -187,7 +187,7 @@ void TargetSettingsPanelWidget::setupUi() void TargetSettingsPanelWidget::currentTargetIndexChanged(int targetIndex, int subIndex) { - if (targetIndex < -1 || targetIndex >= m_project->targets().count()) + if (targetIndex < -1 || targetIndex >= m_targets.count()) return; if (subIndex < -1 || subIndex >= 2) return; @@ -198,16 +198,16 @@ void TargetSettingsPanelWidget::currentTargetIndexChanged(int targetIndex, int s // Target was not actually changed: if (m_currentIndex == targetIndex) { - m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]); + if (m_panelWidgets[subIndex]) + m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]); + else + m_centralWidget->setCurrentWidget(m_noTargetLabel); return; } - // Target has changed: - delete m_panelWidgets[0]; - m_panelWidgets[0] = 0; - delete m_panelWidgets[1]; - m_panelWidgets[1] = 0; + m_currentIndex = targetIndex; + // Target has changed: if (targetIndex == -1) { // no more targets! m_centralWidget->setCurrentWidget(m_noTargetLabel); return; @@ -231,10 +231,12 @@ void TargetSettingsPanelWidget::currentTargetIndexChanged(int targetIndex, int s m_centralWidget->addWidget(buildPanel); m_centralWidget->addWidget(runPanel); + m_centralWidget->setCurrentWidget(subIndex == 0 ? buildPanel : runPanel); + + delete m_panelWidgets[0]; m_panelWidgets[0] = buildPanel; + delete m_panelWidgets[1]; m_panelWidgets[1] = runPanel; - - m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]); } void TargetSettingsPanelWidget::addTarget()