Unsolved QModbusDataUnit bug?
-
There seems to be a bug in QModbusDataUnit::setValue(). This method will not set anything if its internal QVector is empty. After a quick look at the Qt source code, I can't see that this internal vector is initialized anywhere else but in setValues().
QModbusDataUnit reg; reg.setStartAddress(1); reg.setRegisterType(QModbusDataUnit::Coils); reg.setValueCount(1); reg.setValue(0, 1); /* will fail */ qDebug() << reg.value(0); reg.setValues(QVector<quint16>() << 1); /* this works! */ qDebug() << reg.value(0); /* from now on, setValue(0, val) will work as expected */
This behaviour is not documented, as far as I can see, and if it's a bug, I can't see that it is fixed in Qt 5.11.
-
@Erlend-E.-Aasland You can check on Qt bug tracker and file a bug if it is not already the case.
-
you're right, looking at QModbusDataUnit.h
setValue
fails, when m_vector is empty, and it gets only initialized in the constructor or viasetValues
But I wouldn't label it a bug, but a feature request. setValue can be used to edit the quint16 vectors after they are set.
However https://bugreports.qt.io is the appropriate place to go either way.
-