Qt跨线程信号和槽的连接(默认方式是直连和队列的折中)
Qt支持三种类型的信号-槽连接:
1,直接连接,当signal发射时,slot立即调用。此slot在发射signal的那个线程中被执行(不一定是接收对象生存的那个线程)
2,队列连接,当控制权回到对象属于的那个线程的事件循环时,slot被调用。此slot在接收对象生存的那个线程中被执行
3,自动连接(缺省),假如信号发射与接收者在同一个线程中,其行为如直接连接,否则,其行为如队列连接。
连接类型可能通过以向connect()传递参数来指定。注意的是,当发送者与接收者生存在不同的线程中,而事件循环正运行于接收者的线程中,使用直接连接是不安全的。同样的道理,调用生存在不同的线程中的对象的函数也是不是安全的。QObject::connect()本身是线程安全的。
This enum describes the types of connection that can be used between signals and slots. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time.
| Constant | Value | Description |
|---|---|---|
| Qt::AutoConnection | 0 | (default) If the signal is emitted from a different thread than the receiving object, the signal is queued, behaving as Qt::QueuedConnection. Otherwise, the slot is invoked directly, behaving as Qt::DirectConnection. The type of connection is determined when the signal is emitted. |
| Qt::DirectConnection | 1 | The slot is invoked immediately, when the signal is emitted. |
| Qt::QueuedConnection | 2 | The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread. |
| Qt::BlockingQueuedConnection | 4 | Same as QueuedConnection, except the current thread blocks until the slot returns. This connection type should only be used where the emitter and receiver are in different threads. Note: Violating this rule can cause your application to deadlock. |
| Qt::UniqueConnection | 0x80 | Same as AutoConnection, but the connection is made only if it does not duplicate an existing connection. i.e., if the same signal is already connected to the same slot for the same pair of objects, then the connection will fail. This connection type was introduced in Qt 4.6. |
| Qt::AutoCompatConnection | 3 | The default type when Qt 3 support is enabled. Same as AutoConnection but will also cause warnings to be output in certain situations. See Compatibility Signals and Slots for further information. |
With queued connections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message:
QObject::connect: Cannot queue arguments of type 'MyType'
Call qRegisterMetaType() to register the data type before you establish the connection.
When using signals and slots with multiple threads, see Signals and Slots Across Threads.
See also Thread Support in Qt, QObject::connect(), and qRegisterMetaType().
http://blog.csdn.net/seanyxie/article/details/7025183
Qt跨线程信号和槽的连接(默认方式是直连和队列的折中)的更多相关文章
- Qt error ------ qRegisterMetaType() 跨线程信号与槽的形参携带
Qt提示: QObject::connect: Cannot queue arguments of type 'FrequencySpectrum' (Make sure 'FrequencySpec ...
- QT踩坑记录1-多线程信号与槽
QT踩坑记录1-多线程信号与槽 QTC++Bugs 错误输出 无错误输出, 但是声明了信号的连接,但是无法使用 程序中就是无命令 介绍 QT 典型程序 #include <QObject> ...
- PyQt(Python+Qt)学习随笔:使用pyqtConfigure建立信号和槽的连接
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 在PyQt中,一般信号和槽的连接是通过connect方法建立的,语法如下: connect(slot ...
- Qt学习之信号与槽(一)
Qt学习之信号与槽(一) 目录 QT的信号与槽机制 在窗口的UI设计中操作添加信号和槽 QT的信号与槽机制 QT的两种机制 在Qt和PyQt中有两种通信机制: 低级事件处理机制(low-l ...
- Qt入门之信号与槽机制
一. 简介 就我个人来理解,信号槽机制与Windows下消息机制类似,消息机制是基于回调函数,Qt中用信号与槽来代替函数指针,使程序更安全简洁. 信号和槽机制是 Qt 的核心机制,可以让编程人员将互不 ...
- Qt 5中信号和槽的新语法
QT 是一个跨平台的 C++ GUI 应用构架,它提供了丰富的窗口部件集,具有面向对象.易于扩展.真正的组件编程等特点,更为引人注目的是目前 Linux 上最为流行的 KDE 桌面环境就是建立在 QT ...
- Qt5 UI信号、槽自动连接的控件重名
Qt5 UI信号.槽自动连接的控件重名 来源 http://blog.csdn.net/goldenhawking/article/details/51865909 对Qt5稍有熟悉的童鞋都知道信号. ...
- Qt学习笔记----信号与槽实现的四种方式
1.以按钮为例,首先添加一个按钮,对象名为pushButton,在按钮是右键单击选择“转到槽”即可,在转到槽选择面板(右图)里面选择需要进行的操作,比如单击clicked() 2.选择菜单“编辑”,找 ...
- 【2017-07-04】Qt信号与槽深入理解之一:信号与槽的连接方式
今天是个好日子,嗯. 信号槽机制是Qt的特色功能之一,类似于windows中的消息机制,在不同的类对象间传递消息时我们经常使用信号槽机制,然而很多时候都没有去关注connect()函数到底有几种重载的 ...
随机推荐
- 【转】Linux下tar.xz结尾的文件的解压方法
原文网址:http://blog.csdn.net/silvervi/article/details/6325698 今天尝试编译内核,下载到了一份tar.xz结尾的压缩文件,网上解决方法比较少,不过 ...
- HDU3727--Jewel (主席树 静态区间第k大)
Jewel Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- windows 删除服务命令
在dos窗口下执行 sc delete 服务名( 例如 mysql) C:\Program Files\MySQL\MySQL Server 5.6\
- JS截取字符串方法
function textSubstr(str,sub_length){ str = str.trim(); var temp1 = str.replace(/[^\x00-\xff]/g," ...
- javascript 单个图片的淡入淡出效果和多张图片的淡入淡出效果
最近刚好在看之前妙趣网站的javascript 初级运动教程,教程里说设置图片的透明度使用了一个变量.这种方法确实不错,但是燕姐喜欢麻烦.就用自己的理解方法写了一遍.其中也是各种坑.现在先把一个图片的 ...
- Kinect for Windows V2和V1对照开发___彩色数据获取并用OpenCV2.4.10显示
V1彩色分辨率:640x480 V2彩色分辨率:1920x1080 1,打开彩色图像帧的方式 对于V1: 使用NuiImageStreamOpen方法打开 hr = m_PNuiSensor-> ...
- Transparency Tutorial with C# - Part 1
Download demo project - 4 Kb Download source - 6 Kb Download demo project - 5 Kb Download source - 6 ...
- Python字符串方法
capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...
- Sybase常用函数
==================================常用函数===========================================字符串函数1)ISNULL(EXP1, ...
- 在VMware中为Linux系统安装VM-Tools的详解教程
在安装Linux的虚拟机中,单击“虚拟机”菜单下的“安装Vmware-Tools”. 先介绍一下下面安装该工具时要用到的几个目录: /mnt 挂载目录,用来临时挂载别的文件系统,硬件设备 /tmp临时 ...