• QT信号槽: QT实现的观察者机制,可由信号触发槽方法。


    QT信号槽: QT实现的观察者机制,可由信号触发槽方法。 

    QT里没有单独的关键词定义事件,因此:

     1、在系统层面,一般说的事件对QT而言,都是指操作系统层面的事件。

     2、在QT开发层面,事件更多是抽象说法,可以简单理解为:信号和槽是事件实现的一种方式。

    举例:

    当点击一个按钮的时候,QT底层应该是收到了操作系统的某个信号,进而触发了该信号在QT里对应的方法X,QT在这个方法X里又通过信号槽的方式触发开发者相应的代码。

    系统执行方法X的过程可以认为是系统层面的一个事件。

    附注:其他框架可能就是直接在上述的方法X里触发开发者的代码了。

    区别:设计模式上事件一般是私有的,不能直接被外界触发;槽可以由外界通过信号触发。 

    注意:发信号是在接收者线程中执行,直接调用是在调用者线程中执行。

    qt里的事件与信号槽   可以简单理解为  .net里的事件与委托。

     其他参考:

    https://bbs.csdn.net/topics/340136852

    其他参考:

    https://stackoverflow.com/questions/3794649/qt-events-and-signal-slots

    Events are dispatched by the event loop. Each GUI program needs an event loop, whatever you write it Windows or Linux, using Qt, Win32 or any other GUI library. As well each thread has its own event loop. In Qt "GUI Event Loop" (which is the main loop of all Qt applications) is hidden, but you start it calling:

    QApplication a(argc, argv);
    return a.exec();
    

    Messages OS and other applications send to your program are dispatched as events.

    Signals and slots are Qt mechanisms. In the process of compilations using moc (meta-object compiler), they are changed to callback functions.

    Event should have one receiver, which should dispatch it. No one else should get that event.

    All slots connected to the emitted signal will be executed.

    You shouldn't think of Signals as events, because as you can read in the Qt documentation:

    When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop.

    When you send an event, it must wait for some time until the event loop dispatches all events that came earlier. Because of this, execution of the code after sending event or signal is different. Code following sending an event will be run immediately. With the signals and slots mechanisms it depends on the connection type. Normally it will be executed after all slots. Using Qt::QueuedConnection, it will be executed immediately, just like events. Check all connection types in the Qt documentation.

  • 相关阅读:
    链表和递归
    Async and Await
    Linux下如何对目录中的文件进行统计
    Linux系统添加自定义网卡并更改网卡接口
    运维实战:Linux系统扩展oracle数据库所在的分区
    在Linux命令行发送电子邮件附件的两种方法
    Centos7部署轻量级自动化运维工具pssh
    CentOS7中使用systemctl列出启动失败的服务
    AbstractQueuedSynchronizer详解(转)
    Oracle 11g数据导入到10g
  • 原文地址:https://www.cnblogs.com/chinasoft/p/16070499.html
Copyright © 2020-2023  润新知