• 本周技术概要20231016-20231022与生活点滴


    本周包了饺子,辣椒油整的也不错,不过包饺子上升的空间还很大。

    饺子美照:

    3bd93ae10e3d0557fe9fad2ba569a63a.jpeg

    823ab1b387305459af0cddae86c26e8a.jpeg

    一、linux下Qt treeView内存泄漏

    当把原来Qt程序由ubuntu 32位的程序迁移到ubuntu 64位时,测试程序发现了内存泄漏问题,经过排查,最终定位在Qt的treeView的setCurrentIndex调用上。到目前还没有排查出来,有遇到同样问题的同志可以一起交流下。程序测试demo在64位环境下有明显内存泄漏,但是同样程序在32位上运行正常,接下来可能要继续更换Qt的版本进行测试了。

    目前推测就是Qt自身Widget库的问题。

    测试环境:Linux ubuntu 4.15.0-142-generic #146~16.04.1-Ubuntu

    测试程序如下:

    头文件:

    1. /****************************************************************************
    2. **
    3. ** Copyright (C) 2016 The Qt Company Ltd.
    4. ** Contact: https://www.qt.io/licensing/
    5. **
    6. ** This file is part of the examples of the Qt Toolkit.
    7. **
    8. ** $QT_BEGIN_LICENSE:BSD$
    9. ** Commercial License Usage
    10. ** Licensees holding valid commercial Qt licenses may use this file in
    11. ** accordance with the commercial license agreement provided with the
    12. ** Software or, alternatively, in accordance with the terms contained in
    13. ** a written agreement between you and The Qt Company. For licensing terms
    14. ** and conditions see https://www.qt.io/terms-conditions. For further
    15. ** information use the contact form at https://www.qt.io/contact-us.
    16. **
    17. ** BSD License Usage
    18. ** Alternatively, you may use this file under the terms of the BSD license
    19. ** as follows:
    20. **
    21. ** "Redistribution and use in source and binary forms, with or without
    22. ** modification, are permitted provided that the following conditions are
    23. ** met:
    24. ** * Redistributions of source code must retain the above copyright
    25. ** notice, this list of conditions and the following disclaimer.
    26. ** * Redistributions in binary form must reproduce the above copyright
    27. ** notice, this list of conditions and the following disclaimer in
    28. ** the documentation and/or other materials provided with the
    29. ** distribution.
    30. ** * Neither the name of The Qt Company Ltd nor the names of its
    31. ** contributors may be used to endorse or promote products derived
    32. ** from this software without specific prior written permission.
    33. **
    34. **
    35. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    36. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    37. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    38. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    39. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    40. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    41. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    42. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    43. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    44. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    45. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    46. **
    47. ** $QT_END_LICENSE$
    48. **
    49. ****************************************************************************/
    50. #ifndef MAINWINDOW_H
    51. #define MAINWINDOW_H
    52. #include
    53. #include
    54. #include
    55. QT_BEGIN_NAMESPACE
    56. class QTreeView; //forward declarations
    57. class QStandardItemModel;
    58. class QStandardItem;
    59. class QTimer;
    60. QT_END_NAMESPACE
    61. class MainWindow : public QMainWindow
    62. {
    63. Q_OBJECT
    64. private slots:
    65. void slot_valueIncrease();
    66. void slot_modelIndex(QModelIndex index);
    67. private:
    68. QTreeView *treeView;
    69. QTreeView TreeView;
    70. QStandardItemModel *standardModel;
    71. QList prepareRow(const QString &first) const;
    72. QTimer *timer_;
    73. int count{0};
    74. QStandardItem *root_;
    75. QStandardItem *first_;
    76. QStandardItem *second_;
    77. public:
    78. MainWindow(QWidget *parent = nullptr);
    79. };
    80. #endif // MAINWINDOW_H

    cpp文件:

    1. root_ = new QStandardItem("root");
    2. first_ = new QStandardItem("first");
    3. second_ = new QStandardItem("second");
    4. first_->appendRow(second_);
    5. root_->appendRow(first_);
    6. 定时器溢出后:
    7. treeView->setCurrentIndex(first_->index());
    8. treeView->setCurrentIndex(second_->index());

    最后使用top指令观察RES值,会有明显连续增加。程序运行效果:

    c598cf5517378a63e10ccbd9d55e568d.jpeg

    二、linux下

        linux下USB转232、转485、转422的硬件验证

    RS232 DB9接头2脚和三脚短接,实现“环回”

    RS485 是半双工,无法环回。

    RS422 DB9接头,短接13 短接24。

    引脚具体图片:

    1b65ac26c078d12a3b55c01e41cabd7c.jpeg

    RS232

    1a19cdb0af95362b84e356cdc224a181.jpeg

                       RS422

    Linux脚本测试指令:

    1、利用stty命令去掉默认的回显参数

    stty -F /dev/ttyUSB0 -echo -onlcr

    2、一个终端输入:

    cat /dev/ttyUSB0

    1、另一个终端输入

    echo "hello" > /dev/ttyUSB0

    效果如图:

    768f7be5b9fd279d2825324565a19814.jpeg

    757e5a59909c14d93b368ef3117fb6f1.jpeg

    677b0fb3b9ee9ccf1f09f73de1598517.jpeg

    8310bada83e925cd4a42616981370eeb.jpeg

    欢迎大家关注公众号:

    4678e6d1cf14ad465f196d11329ef744.png

  • 相关阅读:
    PHP 数据库交互优化,根据传参查询
    【学习】一致性哈希与哈希环
    Linux中vim程序编辑器使用
    CodeWhisperer 的正确使用
    ufw配置:外网ip禁止访问配置
    java计算机毕业设计html5健身房信息管理系统源码+mysql数据库+系统+lw文档+部署
    HTTP/1.1协议中的响应报文
    露营装备经营商城小程序搭建
    揭秘 Nacos 的 AP 架构 「Distro 一致性协议」(一)
    全新分子图对比学习框架:飞桨社区开发者为你解读顶会论文
  • 原文地址:https://blog.csdn.net/ACK_ACK/article/details/133980597