summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-03-21 10:11:15 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-21 14:50:43 +0100
commit92577874f9fdfcc655510394c38ba70f9e5503b7 (patch)
tree14eaa174d3aa38058d57a4ca33347114f0609291 /examples
parent4d887c58eddc922c8fbab37b54c2825e2a05bcea (diff)
downloadqtserialport-92577874f9fdfcc655510394c38ba70f9e5503b7.tar.gz
Demonstrate the error notification through the terminal example
I have received a couple of requests recently whether it is planned to support error notification and hence I think it would be a good idea to demonstrate its usage inside the examples as much as possible. Here you can find the first attempt for that. As the library aims to provide the error strings as well, all that has to be done is to setup a handler for the notification and display a message box and conditionally close the serial port in case of critical errors. The string will also be provided by the library which makes the interface unified across certain projects. However, the clients can also use their strings if they wish. It is up to their decision. The error strings are already localized and internationalized inside the library. The handler is now also tagged properly for the documentation so that it is more appropriate for end users reading the documentation to get these bits right as it is probably a severe issue for many developers and end users. This will also allow us to be very careful about the error strings inside the library that is among my next goals to make it even nicer than before because currently there is no "high-level" error message prepended to the more detailed one. Hence, this could still be improved in the near future. Some errors are already tested when opening the serial port. Hence, the example can demonstrate both types of error management: sync and async. It might be sometimes more feasible to have a sync error management in place even if async can also work. The change has been tested on Linux and Windows with Qt4, and with Qt5 on Linux for the time being. Thank you for Denis to revealing the importance of the issue even if this patch is representing a bit different approach. Change-Id: If0274e684fd5da08b32bbf0227bfb98784c3a78f Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/terminal/mainwindow.cpp14
-rw-r--r--examples/terminal/mainwindow.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/examples/terminal/mainwindow.cpp b/examples/terminal/mainwindow.cpp
index cde83e1..b394b7d 100644
--- a/examples/terminal/mainwindow.cpp
+++ b/examples/terminal/mainwindow.cpp
@@ -69,6 +69,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui->actionConfigure->setEnabled(true);
initActionsConnections();
+
+ connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
+ SLOT(handleError(QSerialPort::SerialPortError)));
+
//! [2]
connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
//! [2]
@@ -158,6 +162,16 @@ void MainWindow::readData()
}
//! [7]
+//! [8]
+void MainWindow::handleError(QSerialPort::SerialPortError error)
+{
+ if (error == QSerialPort::ResourceError) {
+ QMessageBox::critical(this, tr("Critical Error"), serial->errorString());
+ closeSerialPort();
+ }
+}
+//! [8]
+
void MainWindow::initActionsConnections()
{
connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(openSerialPort()));
diff --git a/examples/terminal/mainwindow.h b/examples/terminal/mainwindow.h
index 357b0b5..1be7f89 100644
--- a/examples/terminal/mainwindow.h
+++ b/examples/terminal/mainwindow.h
@@ -75,6 +75,8 @@ private slots:
void writeData(const QByteArray &data);
void readData();
+ void handleError(QSerialPort::SerialPortError error);
+
private:
void initActionsConnections();