From 730a5492e4780504a80db1a27dc307d8f61b4696 Mon Sep 17 00:00:00 2001 From: Zoltan Padrah Date: Fri, 18 Dec 2020 20:47:55 +0200 Subject: [PATCH] property editor: fix crash when changing a property and clicking circuit apparently Ubuntu 18.04 is affected (Qt 5.9.5) and Ubuntu 20.04 is not (Qt 5.12.8). to reproduce: 1. place and select a resistor 2. in the property editor click on any of its properties, in order to start editing it 3. click on the circuit, to stop editing of the properties 3.1. Expected: property value is kept, program continues 3.2. Actually: crash with the same stack trace from above Should fix issue on GitHub: https://github.com/ktechlab/ktechlab/issues/60 --- src/gui/itemeditor/propertyeditor.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gui/itemeditor/propertyeditor.cpp b/src/gui/itemeditor/propertyeditor.cpp index 88b86842..60821177 100644 --- a/src/gui/itemeditor/propertyeditor.cpp +++ b/src/gui/itemeditor/propertyeditor.cpp @@ -476,8 +476,19 @@ void PropertyEditor::showDefaultsButton(bool show) void PropertyEditor::updateDefaultsButton() { - if (!m_editItem) + QTableWidgetItem *currItem = currentItem(); + if (!currItem) { + m_editItem = nullptr; return; + } + m_editItem = dynamic_cast(currItem); + if (!m_editItem) { + qWarning() << "failed to cast current item to PropertyEditorItem, " << currItem; + return; + } + qDebug() << "currentItem=" << currentItem(); + qDebug() << "m_editItem=" << m_editItem; + qDebug() << "m_editItem->property=" << m_editItem->property(); showDefaultsButton( m_editItem->property()->changed() ); repaint(); // m_editItem->repaint(); } -- GitLab