From 01df1b7a635b11c9d0985f9651cfa4ae3d037890 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 4 Oct 2017 14:32:21 +0200 Subject: CAN-Example: Disable Send button if frame id is empty Every CAN frame needs a CAN-ID to be sent. Disable the Send button with a informative tooltip if this condition is not met. Change-Id: I77033a36c4a45c136185135776ef79185dc548be Reviewed-by: Rolf Eike Beer Reviewed-by: Denis Shienkov Reviewed-by: Alex Blasche --- examples/serialbus/can/sendframebox.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/serialbus/can/sendframebox.cpp b/examples/serialbus/can/sendframebox.cpp index a84222d..d7a25ba 100644 --- a/examples/serialbus/can/sendframebox.cpp +++ b/examples/serialbus/can/sendframebox.cpp @@ -157,6 +157,15 @@ SendFrameBox::SendFrameBox(QWidget *parent) : m_ui->bitrateSwitchBox->setChecked(false); }); + auto frameIdTextChanged = [this]() { + const bool hasFrameId = !m_ui->frameIdEdit->text().isEmpty(); + m_ui->sendButton->setEnabled(hasFrameId); + m_ui->sendButton->setToolTip(hasFrameId + ? QString() : tr("Cannot send because no Frame ID was given.")); + }; + connect(m_ui->frameIdEdit, &QLineEdit::textChanged, frameIdTextChanged); + frameIdTextChanged(); + connect(m_ui->sendButton, &QPushButton::clicked, [this]() { const uint frameId = m_ui->frameIdEdit->text().toUInt(nullptr, 16); QString data = m_ui->payloadEdit->text(); -- cgit v1.2.3