zoukankan      html  css  js  c++  java
  • Qt中信号槽connect的多种类型

    QObject::connect只有4个参数吗?其实不是,请看它的定义:
    QObject::connect(sender, signal, receiver, method, Qt::ConnectionType type = Qt::AutoConnection)
    可见实际它有5个参数,只是最后一个参数有默认值,所以平常使用时很少触及。前4个参数都很熟悉,第五个参数是一个enum Qt::Connection Type类型的,它一共有六个值,下面是Qt Assistant中给出的明确说明:

    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.

    ConstantValueDescription
    Qt::AutoConnection 0 (default) Same as DirectConnection, if the emitter and receiver are in the same thread. Same as QueuedConnection, if the emitter and receiver are in different threads.
    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.

  • 相关阅读:
    Java NIO中的缓冲区Buffer(二)创建/复制缓冲区
    Java NIO中的缓冲区Buffer(一)缓冲区基础
    Java中的反射
    Java SE 9(JDK9)环境安装及交互式编程环境Jshell使用示例
    Spring Data JPA例子[基于Spring Boot、Mysql]
    Spring Session
    Spring Data Redis示例
    Spring IO Platform简介及示例
    使用Spring Boot开发 “Hello World” Web应用
    2017/01/13,今天正好是开通博客园一周年,谈谈自己的一些想法
  • 原文地址:https://www.cnblogs.com/xiaojihua20/p/4108523.html
Copyright © 2011-2022 走看看