diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,6 +32,10 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(&(this->serialPort), &QSerialPort::readyRead, this, &MainWindow::onDataReady); + // init port signals + QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)), + this, SLOT(onPortError(QSerialPort::SerialPortError))); + loadPortList(); loadBaudRateList(); ui->cbBaudRate->setCurrentIndex(ui->cbBaudRate->findText("9600")); @@ -161,6 +165,11 @@ void MainWindow::onDataReady() addData((unsigned char)(data[0])); } +void MainWindow::onPortError(QSerialPort::SerialPortError error) +{ + qDebug() << "Port error happened: " << serialPort.error(); +} + void MainWindow::addData(double data) { // shift data array and place new data at the end diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -38,6 +38,7 @@ private slots: void selectBaudRate(QString baudRate); void onDataReady(); + void onPortError(QSerialPort::SerialPortError error); signals: void portToggled(bool open);