zoukankan      html  css  js  c++  java
  • 回调函数实现类似QT中信号机制(最简单)

    1. 定义回调接口类:

    class UIcallBack
    {
    public:
    virtual void onAppActivated() = 0;
    virtual void onShowMore() = 0;
    };

    2. 定义一个类 继承 回调接口类,并包含你要监听的类
    class AppManager : public UIcallBack
    {
    public:
    AppManager();

    UIManager uiManager;
    ……
    uiManager.setCallBack(this);


    void AppManager::onAppActivated()
    {

    }

    void AppManager::onShowMore()
    {
    _D("callback onshowMore ");
    }


    3. 要监听的类实现
    class UIManager
    {
    public:
    UIManager();
    ~UIManager();

    void setCallBack(UIcallBack *pcallBack)
    {
    m_pcallBack = pcallBack;
    }

    UIcallBack *m_pcallBack;
    };


    在 UIManager里调用
    m_pcallBack->onShowMore();


    则在AppManager类里就能响应到onShowMore()这个消息

    ------------

    2017-10-02 应一位回复此博客的朋友要求,总结另一篇有关QT信号与槽机制的简单实现原理,可参考另一篇博客:

    http://blog.csdn.net/liukang325/article/details/78151601
    ---------------------
    作者:阳光柠檬_
    来源:CSDN
    原文:https://blog.csdn.net/liukang325/article/details/45742675
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Non-Photorealistic Rendering using OpenCV ( Python, C++ )
    Tensorflow Eager execution and interface
    Linear and Logistic Regression in TensorFlow
    TensorFlow Ops
    Introduction to TensorFlow
    Java Syntax Specification
    java方法的虚分派和方法表
    λ演算
    活性变量分析
    java垃圾回收机制
  • 原文地址:https://www.cnblogs.com/findumars/p/9818816.html
Copyright © 2011-2022 走看看