Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.10.1
-
None
Description
If you call the disconnectDevice() method on a QModbusTcpClient object that was not opened or has already been closed, then we would never close and would always be in QModbusDevice::ClosingState.
Status QModbusDevice::ClosingState change to QModbusDevice:: UnconnectedState only when the disconnected signal comes from the internal TcpSocket (see qmodbustcpclient_p.h), but when the socket was not open or has already been closed, signal disconnected is not emitted!
Source code to illustrate:
qmodbusdevice.cpp
void QModbusDevice::disconnectDevice()
{
setState(QModbusDevice::ClosingState);
//Unconnected is set by backend -> might be delayed by event loop
close();
}
qmodbustcpclient.cpp
void QModbusTcpClient::close() { if (state() == QModbusDevice::UnconnectedState) return; Q_D(QModbusTcpClient); d->m_socket->disconnectFromHost(); }
I think we should add an additional check to the method void QModbusTcpClient::close() for reset ClosingState to UnconnectedState