• 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.

  • 相关阅读:
    C语言——enum
    C语言——杂实例
    pc上用C语言模拟51多任务的案例程序
    C语言结构体实例-创建兔子
    C语句模拟多任务实例
    求解1^2+2^2+3^2+4^2+...+n^2的方法(求解1平方加2平方加3平方...加n平方的和)
    啊啊啊哦哦
    2013多校联合3 G The Unsolvable Problem(hdu 4627)
    c#操作excel方式三:使用Microsoft.Office.Interop.Excel.dll读取Excel文件
    揭开Socket编程的面纱
  • 原文地址:https://www.cnblogs.com/chinasoft/p/16070499.html
Copyright © 2020-2023  润新知