Commit 3664d205 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Crash: Fix crash when removing a tool chain

Fix crash on trying to debug an application after the last
tool chain for the Qt version used was removed.

Task-number: QTCREATORBUG-4197
Reviewed-by: dt
parent 6ad7df69
......@@ -72,6 +72,11 @@ BuildConfiguration::BuildConfiguration(Target *target, const QString &id) :
//: Display name of the clean build step list. Used as part of the labels in the project window.
bsl->setDefaultDisplayName(tr("Clean"));
m_stepLists.append(bsl);
connect(ToolChainManager::instance(), SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
this, SLOT(handleToolChainRemovals(ProjectExplorer::ToolChain*)));
connect(ToolChainManager::instance(), SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
this, SLOT(handleToolChainAddition(ProjectExplorer::ToolChain*)));
}
BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *source) :
......@@ -85,6 +90,11 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
// Do not clone stepLists here, do that in the derived constructor instead
// otherwise BuildStepFactories might reject to set up a BuildStep for us
// since we are not yet the derived class!
connect(ToolChainManager::instance(), SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
this, SLOT(handleToolChainRemovals(ProjectExplorer::ToolChain*)));
connect(ToolChainManager::instance(), SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
this, SLOT(handleToolChainAddition(ProjectExplorer::ToolChain*)));
}
BuildConfiguration::~BuildConfiguration()
......@@ -155,6 +165,22 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
return ProjectConfiguration::fromMap(map);
}
void BuildConfiguration::handleToolChainRemovals(ProjectExplorer::ToolChain *tc)
{
if (m_toolChain != tc)
return;
setToolChain(target()->preferredToolChain(this));
}
void BuildConfiguration::handleToolChainAddition(ProjectExplorer::ToolChain *tc)
{
Q_UNUSED(tc);
if (m_toolChain != 0)
return;
setToolChain(target()->preferredToolChain(this));
}
Target *BuildConfiguration::target() const
{
return static_cast<Target *>(parent());
......
......@@ -120,6 +120,10 @@ protected:
virtual bool fromMap(const QVariantMap &map);
private slots:
void handleToolChainRemovals(ProjectExplorer::ToolChain *tc);
void handleToolChainAddition(ProjectExplorer::ToolChain *tc);
private:
bool m_clearSystemEnvironment;
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
......
......@@ -369,8 +369,7 @@ void Qt4BuildConfiguration::setQtVersion(QtVersion *version)
void Qt4BuildConfiguration::setToolChain(ProjectExplorer::ToolChain *tc)
{
Q_ASSERT(qtVersion());
if (!qt4Target()->possibleToolChains(this).contains(tc)
|| tc->restrictedToTargets().contains(target()->id()))
if (tc != 0 && !qt4Target()->possibleToolChains(this).contains(tc))
return;
BuildConfiguration::setToolChain(tc);
......
......@@ -456,15 +456,20 @@ void Qt4ProjectConfigWidget::toolChainChanged()
{
if (m_ignoreChange)
return;
for (int i=0; i < m_ui->toolChainComboBox->count(); ++i) {
for (int i = 0; i < m_ui->toolChainComboBox->count(); ++i) {
ProjectExplorer::ToolChain *tc =
static_cast<ProjectExplorer::ToolChain *>(m_ui->toolChainComboBox->itemData(i, Qt::UserRole).value<void *>());
if (tc == m_buildConfiguration->toolChain()) {
m_ignoreChange = true;
m_ui->toolChainComboBox->setCurrentIndex(i);
m_ignoreChange = false;
return;
}
}
m_ignoreChange = true;
m_ui->toolChainComboBox->addItem(tr("<No tool chain selected>"), qVariantFromValue(static_cast<void *>(0)));
m_ui->toolChainComboBox->setCurrentIndex(m_ui->toolChainComboBox->count() - 1);
m_ignoreChange = false;
}
void Qt4ProjectConfigWidget::updateToolChainCombo()
......@@ -476,20 +481,8 @@ void Qt4ProjectConfigWidget::updateToolChainCombo()
foreach (ProjectExplorer::ToolChain *toolchain, toolchains)
m_ui->toolChainComboBox->addItem(toolchain->displayName(),
qVariantFromValue(static_cast<void *>(toolchain)));
m_ignoreChange = true;
if (!m_buildConfiguration->toolChain() || toolchains.isEmpty()) {
m_ui->toolChainComboBox->addItem(tr("<Invalid tool chain>"), qVariantFromValue(static_cast<void *>(0)));
m_ui->toolChainComboBox->setCurrentIndex(m_ui->toolChainComboBox->count() - 1);
} else if (toolchains.contains(m_buildConfiguration->toolChain())) {
m_ui->toolChainComboBox->setCurrentIndex(toolchains.indexOf(m_buildConfiguration->toolChain()));
} else { // reset to some sensible tool chain
ToolChain *tc = 0;
if (!toolchains.isEmpty())
tc = toolchains.at(0);
m_buildConfiguration->setToolChain(tc);
}
m_ignoreChange = false;
m_ui->toolChainComboBox->setEnabled(toolchains.size() > 1);
toolChainChanged();
}
void Qt4ProjectConfigWidget::toolChainSelected(int index)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment