Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66648

QModbusTcpClient never close on disconnect

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.11.0
    • 5.10.1
    • SerialBus: MOD Bus
    • 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

      Attachments

        For Gerrit Dashboard: QTBUG-66648
        # Subject Branch Project Status CR V

        Activity

          People

            ablasche Alex Blasche
            koynovstas Stas Koynov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes