<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QModbusTCP doesn&#x27;t change state nor fire error when disconnected]]></title><description><![CDATA[<p dir="auto">I'm facing a lot of issues using <code>QModbus</code> classes. For example, if I successfully connect to a device:</p>
<pre><code>QModbusClient *_modbus;

bool ModbusClient::open(QString host, int port)
{
    if (_modbus)
    {
        _modbus-&gt;disconnectDevice();
        delete _modbus;
    }

    _modbus = new QModbusTcpClient(this);
    _modbus-&gt;setConnectionParameter(QModbusDevice::NetworkPortParameter, port);
    _modbus-&gt;setConnectionParameter(QModbusDevice::NetworkAddressParameter, host);

    _modbus-&gt;setTimeout(250);
    _modbus-&gt;setNumberOfRetries(1);

    connect(_modbus, &amp;QModbusDevice::stateChanged,this, &amp;ModbusClient::stateChanged);
    connect(_modbus, &amp;QModbusDevice::errorOccurred,this, &amp;ModbusClient::errorOccurred);

    return _modbus-&gt;connectDevice();
}

void ModbusClient::stateChanged(QModbusDevice::State state)
{
    qDebug() &lt;&lt; "state" &lt;&lt; state;
}

void ModbusClient::errorOccurred(QModbusDevice::Error error)
{
    qDebug() &lt;&lt; "error"&lt;&lt; error;
}
</code></pre>
<p dir="auto">then I disconnect the cable from the device, but <strong>neither the state changes to <code>UnconnectedState</code> nor the error signal is emitted.</strong></p>
<p dir="auto">So, how to detect such a disconnection?</p>
]]></description><link>https://forum.qt.io/topic/95741/qmodbustcp-doesn-t-change-state-nor-fire-error-when-disconnected</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 17:32:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/95741.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 20 Oct 2018 03:27:19 GMT</pubDate><ttl>60</ttl></channel></rss>