前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >本周技术概要20231016-20231022与生活点滴

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

作者头像
用户5908113
发布2023-10-25 17:06:08
1590
发布2023-10-25 17:06:08
举报
文章被收录于专栏:Pou光明Pou光明

一、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

测试程序如下:

头文件:

代码语言:javascript
复制
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QModelIndex>
#include <QTreeView>

QT_BEGIN_NAMESPACE
class QTreeView; //forward declarations
class QStandardItemModel;
class QStandardItem;
class QTimer;

QT_END_NAMESPACE


class MainWindow : public QMainWindow
{
    Q_OBJECT

private slots:
    void slot_valueIncrease();
    void slot_modelIndex(QModelIndex index);

private:
    QTreeView *treeView;

    QTreeView TreeView;

    QStandardItemModel *standardModel;
    QList<QStandardItem *> prepareRow(const QString &first) const;

    QTimer *timer_;
    int count{0};

    QStandardItem *root_;
    QStandardItem *first_;
    QStandardItem *second_;


public:
    MainWindow(QWidget *parent = nullptr);
};

#endif // MAINWINDOW_H

cpp文件:

代码语言:javascript
复制
    root_ = new QStandardItem("root");
    first_ = new QStandardItem("first");
    second_ = new QStandardItem("second");

    first_->appendRow(second_);
    root_->appendRow(first_);
定时器溢出后:
    treeView->setCurrentIndex(first_->index());
    treeView->setCurrentIndex(second_->index());

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

二、linux下

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

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

RS485 是半双工,无法环回。

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

引脚具体图片:

RS232

RS422

Linux脚本测试指令:

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

stty -F /dev/ttyUSB0 -echo -onlcr

2、一个终端输入:

cat /dev/ttyUSB0

1、另一个终端输入

echo "hello" > /dev/ttyUSB0

效果如图:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-10-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Pou光明 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档