serialportcommander: Add Qt6 support

This commit is contained in:
Simon Stürz 2025-08-08 16:11:53 +02:00
parent 878f727e1c
commit 70d6519409
3 changed files with 20 additions and 17 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * 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.")); 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(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError)));
connect(serialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead())); #endif
connect(serialPort, SIGNAL(baudRateChanged(qint32, QSerialPort::Directions)), this, SLOT(onBaudRateChanged(qint32, QSerialPort::Directions))); connect(serialPort, &QSerialPort::readyRead, this, &IntegrationPluginSerialPortCommander::onReadyRead);
connect(serialPort, SIGNAL(parityChanged(QSerialPort::Parity)), this, SLOT(onParityChanged(QSerialPort::Parity))); connect(serialPort, &QSerialPort::baudRateChanged, this, &IntegrationPluginSerialPortCommander::onBaudRateChanged);
connect(serialPort, SIGNAL(dataBitsChanged(QSerialPort::DataBits)), this, SLOT(onDataBitsChanged(QSerialPort::DataBits))); connect(serialPort, &QSerialPort::parityChanged, this, &IntegrationPluginSerialPortCommander::onParityChanged);
connect(serialPort, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(onStopBitsChanged(QSerialPort::StopBits))); connect(serialPort, &QSerialPort::dataBitsChanged, this, &IntegrationPluginSerialPortCommander::onDataBitsChanged);
connect(serialPort, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(onFlowControlChanged(QSerialPort::FlowControl))); connect(serialPort, &QSerialPort::stopBitsChanged, this, &IntegrationPluginSerialPortCommander::onStopBitsChanged);
connect(serialPort, &QSerialPort::flowControlChanged, this, &IntegrationPluginSerialPortCommander::onFlowControlChanged);
m_serialPorts.insert(thing, serialPort); m_serialPorts.insert(thing, serialPort);
thing->setStateValue(serialPortCommanderConnectedStateTypeId, true); thing->setStateValue(serialPortCommanderConnectedStateTypeId, true);
} }
@ -171,13 +177,13 @@ void IntegrationPluginSerialPortCommander::onReadyRead()
while (!serialPort->atEnd()) { while (!serialPort->atEnd()) {
data.append(serialPort->read(100)); data.append(serialPort->read(100));
} }
qDebug(dcSerialPortCommander()) << "Message received" << data; qCDebug(dcSerialPortCommander()) << "Message received" << data;
Event event(serialPortCommanderTriggeredEventTypeId, thing->id()); Event event(serialPortCommanderTriggeredEventTypeId, thing->id());
ParamList parameters; ParamList parameters;
parameters.append(Param(serialPortCommanderTriggeredEventInputDataParamTypeId, data)); parameters.append(Param(serialPortCommanderTriggeredEventInputDataParamTypeId, data));
event.setParams(parameters); event.setParams(parameters);
emitEvent(event); emit emitEvent(event);
} }
void IntegrationPluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error) void IntegrationPluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error)

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -31,7 +31,7 @@
#ifndef INTEGRATIONPLUGINSERIALPORTCOMMANDER_H #ifndef INTEGRATIONPLUGINSERIALPORTCOMMANDER_H
#define INTEGRATIONPLUGINSERIALPORTCOMMANDER_H #define INTEGRATIONPLUGINSERIALPORTCOMMANDER_H
#include "integrations/integrationplugin.h" #include <integrations/integrationplugin.h>
#include <QTimer> #include <QTimer>
#include <QSerialPort> #include <QSerialPort>

View File

@ -1,12 +1,9 @@
include(../plugins.pri) include(../plugins.pri)
QT += serialport QT *= serialport
TARGET = $$qtLibraryTarget(nymea_integrationpluginserialportcommander)
SOURCES += \ SOURCES += \
integrationpluginserialportcommander.cpp \ integrationpluginserialportcommander.cpp
HEADERS += \ HEADERS += \
integrationpluginserialportcommander.h \ integrationpluginserialportcommander.h