Qt5.9.9 关于界面拖动导致QModbusRTU(QModbusTCP没有测试过)离线的问题

问题锁定

参考网友的思路:

Qt5.9 Modbus request timeout 0x5异常解决

  1. 网友认为是Qt的bug, 我也认同;
  2. 网友认为可以更新模块, 我也认同, 我也编译了Qt5.15.0的code并成功安装到Qt5.9.9中进行使用,界面拖动QModbusRTU离线问题解决!
    Note: 为什么使用Qt5.15.0, 因为其他更高的版本改动较大,已经更Qt5.9.9差异变大了,移植到Qt5.9.9恐怕会有问题

编译Qt5.15.0 QSerialbus模块步骤

1. 下载QtSerialBus 5.15.0 模块, 只下载模块就好

https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/5.15/5.15.0/submodules/
在这里插入图片描述

2. 解压,使用Qt Creator 打开里面的qtserialbus.pro, 点击编译, 编译之后报错如3

3. 错误罗列如下

  1. Qt::hex 全局替换成 hex
  2. Qt::endl 全局替换成endl
  3. Qt:: hex 全局替换成hex
  4. qmodbustcpclient_p.h
setupTcpSocket()&QAbstractSocket::errorOccurred 改为-static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error)
  1. qmodbusserver.cpp
    增加头文件
#include <bitset>

QModbusServerPrivate::readBits 函数内

// Using byteCount * 8 so the remaining bits in the last byte are zero
    QBitArray bytes(byteCount * 8);

    address = 0; // The data range now starts with zero.
    for ( ; address < count; ++address)
        bytes.setBit(address, unit.value(address));

    QByteArray payload = QByteArray::fromRawData(bytes.bits(), byteCount);
    payload.prepend(char(byteCount));
    return QModbusResponse(request.functionCode(), payload);

替换成

address = 0; // The data range now starts with zero.
    QVector<quint8> bytes;
    for (int i = 0; i < byteCount; ++i) {
        std::bitset<8> byte;
        // According to the spec: If the returned quantity is not a multiple of eight,
        // the remaining bits in the final data byte will be padded with zeros.
        for (int currentBit = 0; currentBit < 8; ++currentBit)
            byte[currentBit] = unit.value(address++); // The padding happens inside value().
        bytes.append(static_cast<quint8> (byte.to_ulong()));
    }

return QModbusResponse(request.functionCode(), byteCount, bytes);
4. 最终编译, 编译通过, 在项目中添加install指令使模块安装到Qt5.9.9中

在这里插入图片描述
执行即可, 或创建新的编译, 最后再检查是否更新到Qt5.9.9的模块中了!

如下代表着有新的Qt5.15.0的QSerialbus库安装到Qt5.9.9中了
在这里插入图片描述

Note: 注意编译流程和安装流程是否有错, 要排错, 否则不一定完整安装!

相关推荐

  1. 解决Qt线安装问题

    2024-07-10 00:52:05       22 阅读
  2. 处理导入Excel文件导致Zip bomb detected问题

    2024-07-10 00:52:05       22 阅读
  3. vscode线方式远程到没有网络服务器上

    2024-07-10 00:52:05       16 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 00:52:05       49 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 00:52:05       53 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 00:52:05       42 阅读
  4. Python语言-面向对象

    2024-07-10 00:52:05       53 阅读

热门阅读

  1. Docker实战教程(一)

    2024-07-10 00:52:05       20 阅读
  2. Visual Studio编译优化选项

    2024-07-10 00:52:05       16 阅读
  3. Pywinauto:强大的Windows 应用程序测试工具

    2024-07-10 00:52:05       20 阅读
  4. Linux grep技巧 结合awk查询

    2024-07-10 00:52:05       14 阅读
  5. Appium:强大的移动应用测试工具

    2024-07-10 00:52:05       19 阅读
  6. 宝塔-Linux模板常用命令-centos7

    2024-07-10 00:52:05       15 阅读
  7. 仙人掌中的SNMP检测不到服务器

    2024-07-10 00:52:05       18 阅读
  8. 算法力扣刷题 三十四【71.简化路径】

    2024-07-10 00:52:05       18 阅读
  9. yolov5:Conv类参数量计算

    2024-07-10 00:52:05       23 阅读
  10. GitHub每日最火火火项目(7.9)

    2024-07-10 00:52:05       19 阅读