Python: do not access deleted widget in settingspage

Change-Id: Ibf7148255ac5a3bb26ec41684f7c96dd5c357ca5
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2024-10-22 10:50:08 +02:00
parent 74068743b6
commit 48c311b8f3

View File

@@ -318,33 +318,27 @@ public:
setCategory(Constants::C_PYTHON_SETTINGS_CATEGORY); setCategory(Constants::C_PYTHON_SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("Python")); setDisplayCategory(Tr::tr("Python"));
setCategoryIconPath(":/python/images/settingscategory_python.png"); setCategoryIconPath(":/python/images/settingscategory_python.png");
setWidgetCreator([this] { m_widget = new InterpreterOptionsWidget; return m_widget; }); setWidgetCreator([] { return new InterpreterOptionsWidget(); });
} }
QList<Interpreter> interpreters() QList<Interpreter> interpreters()
{ {
if (m_widget) return static_cast<InterpreterOptionsWidget *>(widget())->interpreters();
return m_widget->interpreters();
return {};
} }
void addInterpreter(const Interpreter &interpreter) void addInterpreter(const Interpreter &interpreter)
{ {
if (m_widget) static_cast<InterpreterOptionsWidget *>(widget())->addInterpreter(interpreter);
m_widget->addInterpreter(interpreter);
} }
void removeInterpreterFrom(const QString &detectionSource) void removeInterpreterFrom(const QString &detectionSource)
{ {
if (m_widget) static_cast<InterpreterOptionsWidget *>(widget())->removeInterpreterFrom(detectionSource);
m_widget->removeInterpreterFrom(detectionSource);
} }
QList<Interpreter> interpreterFrom(const QString &detectionSource) QList<Interpreter> interpreterFrom(const QString &detectionSource)
{ {
if (m_widget) return static_cast<InterpreterOptionsWidget *>(widget())->interpreterFrom(detectionSource);
return m_widget->interpreterFrom(detectionSource);
return {};
} }
QStringList keywords() const final QStringList keywords() const final
@@ -358,9 +352,6 @@ public:
Tr::tr("&Make Default") Tr::tr("&Make Default")
}; };
} }
private:
InterpreterOptionsWidget *m_widget = nullptr;
}; };
static InterpreterOptionsPage &interpreterOptionsPage() static InterpreterOptionsPage &interpreterOptionsPage()