我有问题-Qt篇(1)
来源:互联网 发布:创维32e500e数据 编辑:程序博客网 时间:2024/05/22 06:49
第一次写博客,以后准备把问题记在博客里面方便回顾。
今天想给串口调试助手加一个连接提示窗口,里面有一个动画用线程做的,把串口对象放在run函数里面然后想用readyRead信号去读取串口数据结果没有任何反应。后来想到对象是在次线程里建立的,主线程收不到信号了。然后想出的解决办法是首先在主线程创建对象,然后调用moveToThread移到次线程里面,open之后再移回主线程。问题解决。
//主线程 sp=new QSerialPort(ui->cbPortNames->currentText()); pothread=new PortOpenThread(ui->cbPortNames->currentText(),sp); sp->moveToThread(pothread); connect(pothread,SIGNAL(beginconnect()),this,SLOT(BeginConnect())); connect(pothread,SIGNAL(endconnect(bool)),this,SLOT(EndConnect(bool))); connect(sp,SIGNAL(readyRead()),this,SLOT(Read())); pothread->start();//子线程 emit beginconnect(); m_sp->open(QIODevice::ReadWrite); emit endconnect(m_sp->isOpen()); if(m_sp->isOpen()) { m_sp->setDataTerminalReady(true); m_sp->setBaudRate(QSerialPort::Baud57600); m_sp->setDataBits(QSerialPort::Data8); m_sp->setParity(QSerialPort::NoParity); m_sp->setStopBits(QSerialPort::OneStop); m_sp->setFlowControl(QSerialPort::NoFlowControl); } m_sp->moveToThread(QApplication::instance()->thread());
阅读全文
0 0
- 我有问题-Qt篇(1)
- 我有个问题
- 我有个问题
- 我有个问题
- 我的RP有问题!
- 我有问题要问
- 有问题请联系我
- 我有一个问题想知道
- Qt编码问题(1)
- QT问题系列(1)
- 我的QT编程问题不完全统计
- 【跟我一起开辟Qt之路】(1)Qt 和Qt Creator简介
- 首页交易状态同步问题--底部工具栏有我的(我的里面有用户名)
- 我的USB设备有问题
- 我的博客首页好像有问题
- 是误解,还是我自己有问题!?
- 面试官,我有问题要问
- 我承认本人理解能力有问题
- hdoj1028 Ignatius and the Princess III(母函数,生成函数)
- 学术论文你该怎么写
- POJ 1375 Intervals 笔记
- HDU
- java开发者的福音, 功能齐全的Integer类
- 我有问题-Qt篇(1)
- android_apktool工具的使用
- android Retrofit简单使用及源码分析
- 二叉搜索树(Binary Search Trees)小结
- bzoj 4129: Haruna’s Breakfast 树上带修改莫队+分块
- RxJava 详解
- JavaScript对象
- 浏览器对象
- 根据秒数转换剩余几天几时几分