Question

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.

Was it helpful?

Solution

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top