Updating pointer using signals and slots

女生的网名这么多〃 提交于 2019-12-06 08:46:15

You're insisting on doing the wrong thing, why? Just send the Sample itself:

void Update(sample);
//...
sample a("MSalters", "the Netherlands");
emit Update(a);

Unless you've determined that this code is a performance bottleneck you would be better to just pass a copy of the object rather than a pointer.

Really, I mean it.

However, if you must use pointers then use a boost::shared_ptr and it will delete itself.

void Update(boost::shared_ptr<sample> s);

void sampleFunction()
{
    boost::shared_ptr<sample> a = boost::shared_ptr<sample>(new sample());
    a->name = "Sachin Tendulkar";
    a->address = "India"
    emit Update(a);    
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!