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(); }