From 70d6519409128a50c3a91a470994249666691c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 8 Aug 2025 16:11:53 +0200 Subject: [PATCH] serialportcommander: Add Qt6 support --- .../integrationpluginserialportcommander.cpp | 24 ++++++++++++------- .../integrationpluginserialportcommander.h | 4 ++-- serialportcommander/serialportcommander.pro | 9 +++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/serialportcommander/integrationpluginserialportcommander.cpp b/serialportcommander/integrationpluginserialportcommander.cpp index 5de0338d..93feab53 100644 --- a/serialportcommander/integrationpluginserialportcommander.cpp +++ b/serialportcommander/integrationpluginserialportcommander.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -109,13 +109,19 @@ void IntegrationPluginSerialPortCommander::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Could not open serial port.")); } +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + connect(serialPort, &QSerialPort::errorOccurred, this, &IntegrationPluginSerialPortCommander::onSerialError); +#else connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError))); - connect(serialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead())); - connect(serialPort, SIGNAL(baudRateChanged(qint32, QSerialPort::Directions)), this, SLOT(onBaudRateChanged(qint32, QSerialPort::Directions))); - connect(serialPort, SIGNAL(parityChanged(QSerialPort::Parity)), this, SLOT(onParityChanged(QSerialPort::Parity))); - connect(serialPort, SIGNAL(dataBitsChanged(QSerialPort::DataBits)), this, SLOT(onDataBitsChanged(QSerialPort::DataBits))); - connect(serialPort, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(onStopBitsChanged(QSerialPort::StopBits))); - connect(serialPort, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(onFlowControlChanged(QSerialPort::FlowControl))); +#endif + connect(serialPort, &QSerialPort::readyRead, this, &IntegrationPluginSerialPortCommander::onReadyRead); + connect(serialPort, &QSerialPort::baudRateChanged, this, &IntegrationPluginSerialPortCommander::onBaudRateChanged); + connect(serialPort, &QSerialPort::parityChanged, this, &IntegrationPluginSerialPortCommander::onParityChanged); + connect(serialPort, &QSerialPort::dataBitsChanged, this, &IntegrationPluginSerialPortCommander::onDataBitsChanged); + connect(serialPort, &QSerialPort::stopBitsChanged, this, &IntegrationPluginSerialPortCommander::onStopBitsChanged); + connect(serialPort, &QSerialPort::flowControlChanged, this, &IntegrationPluginSerialPortCommander::onFlowControlChanged); + + m_serialPorts.insert(thing, serialPort); thing->setStateValue(serialPortCommanderConnectedStateTypeId, true); } @@ -171,13 +177,13 @@ void IntegrationPluginSerialPortCommander::onReadyRead() while (!serialPort->atEnd()) { data.append(serialPort->read(100)); } - qDebug(dcSerialPortCommander()) << "Message received" << data; + qCDebug(dcSerialPortCommander()) << "Message received" << data; Event event(serialPortCommanderTriggeredEventTypeId, thing->id()); ParamList parameters; parameters.append(Param(serialPortCommanderTriggeredEventInputDataParamTypeId, data)); event.setParams(parameters); - emitEvent(event); + emit emitEvent(event); } void IntegrationPluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error) diff --git a/serialportcommander/integrationpluginserialportcommander.h b/serialportcommander/integrationpluginserialportcommander.h index f2e88293..79943929 100644 --- a/serialportcommander/integrationpluginserialportcommander.h +++ b/serialportcommander/integrationpluginserialportcommander.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,7 +31,7 @@ #ifndef INTEGRATIONPLUGINSERIALPORTCOMMANDER_H #define INTEGRATIONPLUGINSERIALPORTCOMMANDER_H -#include "integrations/integrationplugin.h" +#include #include #include diff --git a/serialportcommander/serialportcommander.pro b/serialportcommander/serialportcommander.pro index df14d777..6da03f9a 100644 --- a/serialportcommander/serialportcommander.pro +++ b/serialportcommander/serialportcommander.pro @@ -1,12 +1,9 @@ include(../plugins.pri) -QT += serialport - -TARGET = $$qtLibraryTarget(nymea_integrationpluginserialportcommander) +QT *= serialport SOURCES += \ - integrationpluginserialportcommander.cpp \ - + integrationpluginserialportcommander.cpp HEADERS += \ - integrationpluginserialportcommander.h \ + integrationpluginserialportcommander.h