zoukankan      html  css  js  c++  java
  • boost第 4 章 事件处理

    http://zh.highscore.de/cpp/boost/

    1、信号 Signals

    2、一旦对象 被销毁,连接就会自动释放。

    让 FF类继承自 boost::signals::trackable

    下面的代码 hello() wow()函数不会执行,因为对象w释放之后,连接自动释放了

    #include "mp.h"
    #include <qdebug.h>
    #include <boost/signals2.hpp>
    #include <boost/bind.hpp> 
    
    class FF: public boost::signals2::trackable
    {
    public:
        void hello() const
        {
            qDebug() << "hello, world!";
        }
    
        void wow() const
        {
            qDebug() << "wow, world!";
        }
    
        ~FF()
        {
            qDebug() << "auto delete!";
        }
    
    };
    
    
    
    
    mp::mp(QWidget *parent)
        : QMainWindow(parent)
    {
        ui.setupUi(this);
    
    
        connect(ui.actiony, SIGNAL(triggered()), this, SLOT(opencalc()));
    
    }
    
    mp::~mp()
    {
    
    }
    
    void mp::opencalc()
    {
    
        boost::signals2::signal<void()> s;
        {
            std::auto_ptr<FF> w(new FF());
            s.connect(boost::bind(&FF::hello, w.get()));
            s.connect(boost::bind(&FF::wow, w.get()));
    
        }
        
        s();
        
    
    }
  • 相关阅读:
    HDU 3547 DIY Cube
    POJ 2975 Nim
    POJ 1678 I Love this Game!
    POJ 2234 Matches Game
    POJ 3537 Crosses and Crosses
    POJ 3710 Christmas Game
    POJ 1704 Georgia and Bob
    HDU 3923 Invoker
    POJ 2154 Color
    PLM更新自定义CLASS
  • 原文地址:https://www.cnblogs.com/zhangxuan/p/10517732.html
Copyright © 2011-2022 走看看