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

View File

@@ -68,9 +68,11 @@ signals:
void capabilitiesUpdated(const QString &clientName); void capabilitiesUpdated(const QString &clientName);
private: private:
void onInspectorClosed();
QMap<QString, std::list<LspLogMessage>> m_logs; QMap<QString, std::list<LspLogMessage>> m_logs;
QMap<QString, Capabilities> m_capabilities; QMap<QString, Capabilities> m_capabilities;
QPointer<QWidget> m_currentWidget; QWidget *m_currentWidget = nullptr;
int m_logSize = 100; // default log size if no widget is currently visible int m_logSize = 100; // default log size if no widget is currently visible
}; };