• QSocketNotifier: Socket notifiers cannot be enabled or disabled from another(转)


    在使用Qt开发多线程、socket通讯功能时,遇到以下两个问题:

    QSocketNotifier: Socket notifiers cannot be enabled or disabled from another

    QObject: Cannot create children for a parent that is in a different thread.

    经过大量试错,发现出现这样的问题的根本原因,是在调用MoveToThread函数执行多线程操作后,在目标对象的槽函数中存在目标对象的私有成员中进行了new操作,并且将this指针传给了构造函数。

    总结了两种可以解决问题的方法:

    1.new时不传递this指针

    object = new QModbusTcpClient();
    2.将new操作放在目标对象的构造函数中

    Modbus::Modbus(QObject *parent) : QObject(parent)
    {
    object = new QModbusTcpClient(this);
    }
    3.使用信号与槽的方法调用方法
    ————————————————
    原文链接:https://blog.csdn.net/qq_38344751/article/details/125745945

  • 相关阅读:
    往鼠标位置写入 诗词
    shell条件判断
    shell 案例一
    Shell中的变量
    echo e 命令详解
    Docker 安装RedisJSON 与使用
    Python 插入数据库的各种方式
    Python压缩文件/文件夹
    shell运算符
    关于CAN总线简单总结
  • 原文地址:https://www.cnblogs.com/xihong2014/p/16854453.html
Copyright © 2020-2023  润新知