码迷,mamicode.com
首页 > 其他好文 > 详细

回调函数使用方法二

时间:2015-06-16 18:46:31      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

class CRegAuto : public QObject
{
     Q_OBJECT
public:
    static CRegAuto *getInstance();
    static void ClearInstance();

    typedef void (CRegAuto::*Callback)(int value);
    QHash<int, Callback> cheatCommands;
    void Initialize();
    void processCallBack();
    void add(int value);
    void jian(int);
    void cheng(int);
    void chufa(int);
}

void CRegAuto::jian(int value)
{
    int b = value;
}

void CRegAuto::cheng(int value)
{
    int c = value;
}

void CRegAuto::chufa(int value)
{
    int d = value;
}

void CRegAuto::Initialize()
{
    if (cheatCommands.isEmpty())
    {
        cheatCommands[0] = &CRegAuto::add;
        cheatCommands[1] = &CRegAuto::jian;
        cheatCommands[2] = &CRegAuto::cheng;
        cheatCommands[3] = &CRegAuto::chufa;
    }
     processCallBack();
}

void CRegAuto::processCallBack()
{
    for (int i = 0; i < 4; i++)
    {
        Callback callback = cheatCommands[i];
        if (callback) {
            (this->*callback)(i);
        }
    }
}

 

回调函数使用方法二

标签:

原文地址:http://www.cnblogs.com/Travis990/p/4581108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!