回调函数使用方法二
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);
        }
    }
}

 

posted on 2015-06-16 16:15  pTrack  阅读(402)  评论(0编辑  收藏  举报