Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QModbusDataUnit bug?
Qt 6.11 is out! See what's new in the release blog

QModbusDataUnit bug?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 949 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Erlend E. Aasland
    wrote on last edited by
    #1

    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.

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • E Erlend E. Aasland

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Erlend-E.-Aasland You can check on Qt bug tracker and file a bug if it is not already the case.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • E Erlend E. Aasland

        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.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Erlend-E.-Aasland

        you're right, looking at QModbusDataUnit.h

        setValue fails, when m_vector is empty, and it gets only initialized in the constructor or via setValues

        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.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • E Offline
          E Offline
          Erlend E. Aasland
          wrote on last edited by
          #4

          @jsulm & @J-Hilk: Thanks, I'll check the bug tracker. Thought I'd just post it here first, in case there was something I'd failed to notice in the documentation.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved