From c613fb01186e5687d79fe246cdd48c211003792a Mon Sep 17 00:00:00 2001 From: FabianInostroza Date: Tue, 4 Aug 2015 18:51:03 -0300 Subject: [PATCH] Now builds on Qt5 --- README.txt | 3 +++ main.cpp | 2 +- mainwindow.h | 4 +-- plot.cpp | 35 ++++++++++++------------- qSerialTerm.pro | 11 ++++++-- serialportwidget.cpp | 62 +++++++++++++++++++++----------------------- serialportwidget.h | 8 +++--- 7 files changed, 66 insertions(+), 59 deletions(-) diff --git a/README.txt b/README.txt index f8febbc..ce2bb29 100644 --- a/README.txt +++ b/README.txt @@ -27,6 +27,9 @@ https://github.com/JorgeAparicio/qSerialTerm/wiki BUILDING ======== +Maybe you'll have to compile qwt from sources. +I tested with qwt6 static lib compiled from sources on +Debian Jessie. $ qmake $ make diff --git a/main.cpp b/main.cpp index 26152b3..5de3f05 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ * along with qSerialTerm. If not, see . */ -#include +#include #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/mainwindow.h b/mainwindow.h index 072cc2c..1a26d59 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -23,8 +23,8 @@ #include #include -#include -#include +#include +#include #include "aboutdialog.h" #include "imagewidget.h" diff --git a/plot.cpp b/plot.cpp index 43ef673..7a36c76 100644 --- a/plot.cpp +++ b/plot.cpp @@ -46,22 +46,22 @@ Plot::Plot(size_t numberOfSamples, qreal minY, qreal maxY, QWidget *parent) : curve->setData(circularBuffer); curve->attach(ui->plot); - ui->colorComboBox->addItem("Black", Qt::black); - ui->colorComboBox->addItem("Dark gray", Qt::darkGray); - ui->colorComboBox->addItem("Gray", Qt::gray); - ui->colorComboBox->addItem("Light gray", Qt::lightGray); - ui->colorComboBox->addItem("Red", Qt::red); - ui->colorComboBox->addItem("Green", Qt::green); - ui->colorComboBox->addItem("Blue", Qt::blue); - ui->colorComboBox->addItem("Cyan", Qt::cyan); - ui->colorComboBox->addItem("Magenta", Qt::magenta); - ui->colorComboBox->addItem("Yellow", Qt::yellow); - ui->colorComboBox->addItem("Dark red", Qt::darkRed); - ui->colorComboBox->addItem("Dark green", Qt::darkGreen); - ui->colorComboBox->addItem("Dark blue", Qt::darkBlue); - ui->colorComboBox->addItem("Dark cyan", Qt::darkCyan); - ui->colorComboBox->addItem("Dark magenta", Qt::darkMagenta); - ui->colorComboBox->addItem("Dark yellow", Qt::darkYellow); + ui->colorComboBox->addItem("Black", QColor(Qt::black)); + ui->colorComboBox->addItem("Dark gray", QColor(Qt::darkGray)); + ui->colorComboBox->addItem("Gray", QColor(Qt::gray)); + ui->colorComboBox->addItem("Light gray", QColor(Qt::lightGray)); + ui->colorComboBox->addItem("Red", QColor(Qt::red)); + ui->colorComboBox->addItem("Green", QColor(Qt::green)); + ui->colorComboBox->addItem("Blue", QColor(Qt::blue)); + ui->colorComboBox->addItem("Cyan", QColor(Qt::cyan)); + ui->colorComboBox->addItem("Magenta", QColor(Qt::magenta)); + ui->colorComboBox->addItem("Yellow", QColor(Qt::yellow)); + ui->colorComboBox->addItem("Dark red", QColor(Qt::darkRed)); + ui->colorComboBox->addItem("Dark green", QColor(Qt::darkGreen)); + ui->colorComboBox->addItem("Dark blue", QColor(Qt::darkBlue)); + ui->colorComboBox->addItem("Dark cyan", QColor(Qt::darkCyan)); + ui->colorComboBox->addItem("Dark magenta", QColor(Qt::darkMagenta)); + ui->colorComboBox->addItem("Dark yellow", QColor(Qt::darkYellow)); qsrand(QTime::currentTime().msec()); ui->colorComboBox->setCurrentIndex(qrand() % ui->colorComboBox->count()); @@ -139,8 +139,7 @@ void Plot::on_gridCheckBox_toggled(bool checked) { if (checked) { grid = new QwtPlotGrid; - - grid->setMajPen(QPen(Qt::black, 0, Qt::DashLine)); + grid->setMajorPen(QPen(Qt::black, 0, Qt::DashLine)); grid->attach(ui->plot); ui->plot->replot(); diff --git a/qSerialTerm.pro b/qSerialTerm.pro index 37f0b15..921f2fd 100644 --- a/qSerialTerm.pro +++ b/qSerialTerm.pro @@ -19,13 +19,20 @@ QT += core gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport + +QWT_ROOT = /media/Datos/Programas/libqwt6 + +include ( $$QWT_ROOT/features/qwt.prf ) + win32 { CONFIG += serialport qwt } unix { - LIBS += -lSerialPort -lqwt - INCLUDEPATH += /usr/include/qwt + LIBS += -lQt5SerialPort + #LIBS += -lqwt + #INCLUDEPATH += /usr/include/qwt } TARGET = qSerialTerm diff --git a/serialportwidget.cpp b/serialportwidget.cpp index 028ac98..d8e6739 100644 --- a/serialportwidget.cpp +++ b/serialportwidget.cpp @@ -24,12 +24,10 @@ #define REFRESH_RATE_MS 40 -QT_USE_NAMESPACE_SERIALPORT - -Q_DECLARE_METATYPE(SerialPort::DataBits) -Q_DECLARE_METATYPE(SerialPort::StopBits) -Q_DECLARE_METATYPE(SerialPort::Parity) -Q_DECLARE_METATYPE(SerialPort::FlowControl) +Q_DECLARE_METATYPE(QSerialPort::DataBits) +Q_DECLARE_METATYPE(QSerialPort::StopBits) +Q_DECLARE_METATYPE(QSerialPort::Parity) +Q_DECLARE_METATYPE(QSerialPort::FlowControl) SerialPortWidget::SerialPortWidget(QWidget *parent) : QWidget(parent), @@ -41,44 +39,44 @@ SerialPortWidget::SerialPortWidget(QWidget *parent) : ui->setupUi(this); ui->dataBitsComboBox->addItem(QLatin1String("5"), - SerialPort::Data5); + QSerialPort::Data5); ui->dataBitsComboBox->addItem(QLatin1String("6"), - SerialPort::Data6); + QSerialPort::Data6); ui->dataBitsComboBox->addItem(QLatin1String("7"), - SerialPort::Data7); + QSerialPort::Data7); ui->dataBitsComboBox->addItem(QLatin1String("8"), - SerialPort::Data8); + QSerialPort::Data8); ui->dataBitsComboBox->setCurrentIndex(-1); ui->stopBitsComboBox->addItem(QLatin1String("1"), - SerialPort::OneStop); + QSerialPort::OneStop); ui->stopBitsComboBox->addItem(QLatin1String("1.5"), - SerialPort::OneAndHalfStop); + QSerialPort::OneAndHalfStop); ui->stopBitsComboBox->addItem(QLatin1String("2"), - SerialPort::TwoStop); + QSerialPort::TwoStop); ui->stopBitsComboBox->setCurrentIndex(-1); ui->parityComboBox->addItem(QLatin1String("No"), - SerialPort::NoParity); + QSerialPort::NoParity); ui->parityComboBox->addItem(QLatin1String("Even"), - SerialPort::EvenParity); + QSerialPort::EvenParity); ui->parityComboBox->addItem(QLatin1String("Odd"), - SerialPort::OddParity); + QSerialPort::OddParity); ui->parityComboBox->addItem(QLatin1String("Space"), - SerialPort::SpaceParity); + QSerialPort::SpaceParity); ui->parityComboBox->addItem(QLatin1String("Mark"), - SerialPort::MarkParity); + QSerialPort::MarkParity); ui->parityComboBox->setCurrentIndex(-1); ui->flowControlComboBox->addItem(QLatin1String("No"), - SerialPort::NoFlowControl); + QSerialPort::NoFlowControl); ui->flowControlComboBox->addItem(QLatin1String("Hardware"), - SerialPort::HardwareControl); + QSerialPort::HardwareControl); ui->flowControlComboBox->addItem(QLatin1String("Software"), - SerialPort::SoftwareControl); + QSerialPort::SoftwareControl); ui->flowControlComboBox->setCurrentIndex(-1); } @@ -95,11 +93,11 @@ void SerialPortWidget::write(QByteArray data) void SerialPortWidget::on_getPortsPushButton_clicked() { - serialPortInfoList = SerialPortInfo::availablePorts(); + serialPortInfoList = QSerialPortInfo::availablePorts(); ui->portComboBox->clear(); - foreach(SerialPortInfo entry, serialPortInfoList) + foreach(QSerialPortInfo entry, serialPortInfoList) ui->portComboBox->addItem(entry.portName()); } @@ -130,7 +128,7 @@ void SerialPortWidget::on_openPortPushButton_clicked() ui->parityComboBox->setCurrentIndex(-1); ui->flowControlComboBox->setCurrentIndex(-1); } else { - serialPort = new SerialPort(ui->portComboBox->currentText()); + serialPort = new QSerialPort(ui->portComboBox->currentText()); if (serialPort->open(QIODevice::ReadWrite)) { enableCommunicationSettings(); @@ -201,7 +199,7 @@ void SerialPortWidget::on_portComboBox_currentIndexChanged(int index) } else { ui->openPortPushButton->setEnabled(true); - QList baudRateList = serialPortInfoList[index].standardRates(); + QList baudRateList = serialPortInfoList[index].standardBaudRates(); ui->baudRateComboBox->clear(); @@ -210,14 +208,14 @@ void SerialPortWidget::on_portComboBox_currentIndexChanged(int index) ui->baudRateComboBox->setCurrentIndex(-1); - QString vid = serialPortInfoList[index].vendorIdentifier(); + QString vid = QString(serialPortInfoList[index].vendorIdentifier()); if (vid.isEmpty()) ui->vidLabel->setText(QLatin1String("-")); else ui->vidLabel->setText(QLatin1String("0x") + vid); - QString pid = serialPortInfoList[index].productIdentifier(); + QString pid = QString(serialPortInfoList[index].productIdentifier()); if (pid.isEmpty()) ui->pidLabel->setText(QLatin1String("-")); @@ -233,7 +231,7 @@ void SerialPortWidget::on_portComboBox_currentIndexChanged(int index) void SerialPortWidget::on_baudRateComboBox_currentIndexChanged(int index) { if (index != -1 && serialPort != 0) { - if(serialPort->setRate(ui->baudRateComboBox->itemData(index).value())) { + if(serialPort->setBaudRate(ui->baudRateComboBox->itemData(index).value())) { validateCommunicationSettings(); return; @@ -251,7 +249,7 @@ void SerialPortWidget::on_baudRateComboBox_currentIndexChanged(int index) void SerialPortWidget::on_dataBitsComboBox_currentIndexChanged(int index) { if (index != -1 && serialPort != 0) { - if(serialPort->setDataBits(ui->dataBitsComboBox->itemData(index).value())) { + if(serialPort->setDataBits(ui->dataBitsComboBox->itemData(index).value())) { validateCommunicationSettings(); return; @@ -269,7 +267,7 @@ void SerialPortWidget::on_dataBitsComboBox_currentIndexChanged(int index) void SerialPortWidget::on_stopBitsComboBox_currentIndexChanged(int index) { if (index != -1 && serialPort != 0) { - if(serialPort->setStopBits(ui->stopBitsComboBox->itemData(index).value())) { + if(serialPort->setStopBits(ui->stopBitsComboBox->itemData(index).value())) { validateCommunicationSettings(); return; @@ -287,7 +285,7 @@ void SerialPortWidget::on_stopBitsComboBox_currentIndexChanged(int index) void SerialPortWidget::on_parityComboBox_currentIndexChanged(int index) { if (index != -1 && serialPort != 0) { - if(serialPort->setParity(ui->parityComboBox->itemData(index).value())) { + if(serialPort->setParity(ui->parityComboBox->itemData(index).value())) { validateCommunicationSettings(); return; @@ -305,7 +303,7 @@ void SerialPortWidget::on_parityComboBox_currentIndexChanged(int index) void SerialPortWidget::on_flowControlComboBox_currentIndexChanged(int index) { if (index != -1 && serialPort != 0) { - if(serialPort->setFlowControl(ui->flowControlComboBox->itemData(index).value())) { + if(serialPort->setFlowControl(ui->flowControlComboBox->itemData(index).value())) { validateCommunicationSettings(); return; diff --git a/serialportwidget.h b/serialportwidget.h index 61c84bc..b3d7ab3 100644 --- a/serialportwidget.h +++ b/serialportwidget.h @@ -22,8 +22,8 @@ #include -#include -#include +#include +#include #include @@ -66,8 +66,8 @@ class SerialPortWidget : public QWidget void validateCommunicationSettings(); Ui::SerialPortWidget *ui; - QtAddOn::SerialPort::SerialPort *serialPort; - QList serialPortInfoList; + QSerialPort *serialPort; + QList serialPortInfoList; QTimer *refreshRateTimer; bool isThereCommunication; };