Qt5.5中使用serialport类使得Ui界面很卡
来源:互联网 发布:卓诗尼官方旗舰店淘宝 编辑:程序博客网 时间:2024/06/14 08:28
实际的读取串口工作中出现了这种情况,经过分析问题,可能有以下几个原因。
第一 ,在timer(out)信号触发的readData事件内,出现了非常复杂的循环,程序逻辑问题带来的时间复杂度的增加。
第二,readdata的数据量过大,也就是缓冲去buffer的长度太大了,每个循环中读入的实际数据量远小于maxsize,因此程序就会在forever循环中不停的循环读入数据装入buffersize直到其装满为止。
第三,最容易引起Ui界面卡的原因,就是设置的串口Comm的waitforreadyread(timeout)过大,以至于read动作一直在timeout时间内等待数据的到来,程序处理在这里暂停了timeout时间,这个timeout时间如果超过0.5s,Ui界面自然就卡的不行。
当然,使用waitforreadyread使得Ui变得非常卡的原因就是这个函数阻塞了当前线程。
以下是Qt QIODevice类中有关于这个函数的文档:
bool QIODevice::waitForReadyRead(int msecs)
Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this function will not time out.
Returns true if new data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
If called from within a slot connected to the readyRead() signal, readyRead() will not be reemitted.
Reimplement this function to provide a blocking API for a custom device. The default implementation does nothing, and returns false.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
- Qt5.5中使用serialport类使得Ui界面很卡
- BOS 使得打开UI界面最大化 实现
- Qt5 ui文件使用
- 5、Android中使用AsyncTask异步更新UI界面
- 在VC中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- C#中使用SerialPort类实现简单串口编程
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- C#中使用SerialPort类实现简单串口编程
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- 在C#中使用SerialPort类实现串口通信
- C#中使用SerialPort类实现简单串口编程
- 在C#中使用SerialPort类实现串口通信
- 让div与另一个div覆盖
- 自定义 ListView 实现图片的拉伸放大;松手图片还原
- js获取指定节点对象的样式属性的值的封装函数(兼容ie、Opera和符合w3c标准浏览器)
- C++ Primer 学习笔记——函数(二)
- 1073. Scientific Notation (20)
- Qt5.5中使用serialport类使得Ui界面很卡
- MD5加密工具
- Linux进程调度策略
- 链表堆栈C实现
- IDEA tomcat内存溢出
- 用python 写贪吃蛇AI算法
- nginx正则
- C语言实现矩阵连乘算法
- Objective-C类,对象,方法