From 673495d2eb1fe9cdf701351d75c2203c80ab6ba5 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 28 Apr 2019 14:08:49 +0200 Subject: CAN Example: Fix entering invalid chars in CAN ID input The old code returned Intermediate for invalid inputs (e.g. chars outside the A-F range or special characters), because input.toUInt() returned 0 for these cases. Fix that by checking ok from input.toUInt(&ok) first. To allow clearing an edit field containing valid input with backspace again, an additional isEmpty() check has to be added. Change-Id: I4ae28e35ca21611fc5f323b26cdeca75257f1352 Reviewed-by: Alex Blasche --- examples/serialbus/can/sendframebox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/serialbus') diff --git a/examples/serialbus/can/sendframebox.cpp b/examples/serialbus/can/sendframebox.cpp index 117ff10..13042d0 100644 --- a/examples/serialbus/can/sendframebox.cpp +++ b/examples/serialbus/can/sendframebox.cpp @@ -72,7 +72,7 @@ QValidator::State HexIntegerValidator::validate(QString &input, int &) const bool ok; uint value = input.toUInt(&ok, 16); - if (!value) + if (input.isEmpty()) return Intermediate; if (!ok || value > m_maximum) -- cgit v1.2.3