boost::bind 是否有 QPointer 专业化

发布于 2024-07-24 22:38:36 字数 810 浏览 2 评论 0原文

boost::bind 处理 boost::shared_ptr 的方式与原始指针相同。

QObject * object(new QObject);
boost::shared_ptr<QObject> sharedObject(new QObject);

bind(&QObject::setObjectName, object, _1)( "name" );
bind(&QObject::setObjectName, sharedObject, _1)( "name" );

我希望有一个 boost::bind 来处理 QPointers 作为原始指针。

QPointer<QObject> guardedObject(new QObject);    
// i want to write it like this
bind(&QObject::setObjectName, guardedObject, _1)( "name" );
//now i have to do it like this
bind(&QObject::setObjectName, bind(&QPointer<QObject>::data, guardedObject), _1)( "name" );

有没有人专门研究过QPointer

如果没有,你知道从哪里开始或者需要专门做什么,所以我可以自己做。

boost::bind handles boost::shared_ptr the same way as raw pointers.

QObject * object(new QObject);
boost::shared_ptr<QObject> sharedObject(new QObject);

bind(&QObject::setObjectName, object, _1)( "name" );
bind(&QObject::setObjectName, sharedObject, _1)( "name" );

I would love to have a boost::bind that handles QPointers as raw pointers pointer.

QPointer<QObject> guardedObject(new QObject);    
// i want to write it like this
bind(&QObject::setObjectName, guardedObject, _1)( "name" );
//now i have to do it like this
bind(&QObject::setObjectName, bind(&QPointer<QObject>::data, guardedObject), _1)( "name" );

Is there anyone who has made the specialization for QPointer?

If not do you know where to start or what needs to be specialized, so I can do it myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2024-07-31 22:38:36

添加 get_pointer 函数应该可以解决问题:

namespace boost {
    template<typename T> T * get_pointer(QPointer<T> const& p)
    {
        return p;
    }
}

Adding this overload of the get_pointer function should do the trick:

namespace boost {
    template<typename T> T * get_pointer(QPointer<T> const& p)
    {
        return p;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文