From 8010b046569bd8bdf561b684643dd88153152245 Mon Sep 17 00:00:00 2001 From: Max Wilfinger <6246609+maxwxyz@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:34:12 +0100 Subject: [PATCH] Gui: Handle exception in showValidExpression (#26721) * Gui: Handle exception in showValidExpression If an exception is raised inside showValidExpression() because the expression cannot be evaluated then handle the exception and show it as invalid expression. This fixes issue: https://github.com/FreeCAD/FreeCAD/issues/26501 --------- Co-authored-by: wwmayer --- src/Gui/SpinBox.cpp | 11 +++++++++++ src/Gui/SpinBox.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/Gui/SpinBox.cpp b/src/Gui/SpinBox.cpp index f0eb50e2a6..4f22c75a36 100644 --- a/src/Gui/SpinBox.cpp +++ b/src/Gui/SpinBox.cpp @@ -91,9 +91,20 @@ void ExpressionSpinBox::showInvalidExpression(const QString& tip) p.setColor(QPalette::Active, QPalette::Text, Qt::red); lineedit->setPalette(p); iconLabel->setToolTip(tip); + iconLabel->setPixmap(getIcon(":/icons/button_invalid.svg", QSize(iconHeight, iconHeight))); } void ExpressionSpinBox::showValidExpression(ExpressionSpinBox::Number number) +{ + try { + showExpression(number); + } + catch (const Base::Exception& e) { + showInvalidExpression(QString::fromUtf8(e.what())); + } +} + +void ExpressionSpinBox::showExpression(Number number) { std::unique_ptr result(getExpression()->eval()); auto* value = freecad_cast(result.get()); diff --git a/src/Gui/SpinBox.h b/src/Gui/SpinBox.h index 14d12c50ca..a0124926b6 100644 --- a/src/Gui/SpinBox.h +++ b/src/Gui/SpinBox.h @@ -73,6 +73,9 @@ protected: void drawControl(QStyleOptionSpinBox&); +private: + void showExpression(Number number); + protected: QLineEdit* lineedit; QAbstractSpinBox* spinbox;