LanguageClient: fix crash on inspector widget destruction

Avoid calling functionality of the LspInspectorWidget while it is
destructed by resetting the reference before the deletion.

Change-Id: I335cd1154fe4654be888a0d8cf02a0f6642edcb7
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2023-09-29 06:50:20 +02:00
parent fee2fb638b
commit 278ce651a2
2 changed files with 14 additions and 5 deletions

View File

@@ -341,14 +341,15 @@ private:
void LspInspector::show(const QString &defaultClient)
{
if (!m_currentWidget) {
m_currentWidget = new LspInspectorWidget(this);
m_currentWidget->setAttribute(Qt::WA_DeleteOnClose);
Core::ICore::registerWindow(m_currentWidget, Core::Context("LanguageClient.Inspector"));
auto widget = new LspInspectorWidget(this);
connect(widget, &LspInspectorWidget::finished, this, &LspInspector::onInspectorClosed);
Core::ICore::registerWindow(widget, Core::Context("LanguageClient.Inspector"));
m_currentWidget = widget;
} else {
QApplication::setActiveWindow(m_currentWidget);
}
if (!defaultClient.isEmpty())
static_cast<LspInspectorWidget *>(m_currentWidget.data())->selectClient(defaultClient);
static_cast<LspInspectorWidget *>(m_currentWidget)->selectClient(defaultClient);
m_currentWidget->show();
}
@@ -392,6 +393,12 @@ QList<QString> LspInspector::clients() const
return m_logs.keys();
}
void LspInspector::onInspectorClosed()
{
m_currentWidget->deleteLater();
m_currentWidget = nullptr;
}
LspInspectorWidget::LspInspectorWidget(LspInspector *inspector)
: m_inspector(inspector), m_tabWidget(new QTabWidget(this))
{