C'è una specializzazione QPointer per boost :: bind
-
13-09-2019 - |
Domanda
boost::bind
gestisce boost::shared_ptr
allo stesso modo come puntatori prime.
QObject * object(new QObject);
boost::shared_ptr<QObject> sharedObject(new QObject);
bind(&QObject::setObjectName, object, _1)( "name" );
bind(&QObject::setObjectName, sharedObject, _1)( "name" );
Mi piacerebbe avere un boost::bind
che gestisce QPointers
come puntatore puntatori prime.
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" );
C'è qualcuno che ha fatto la specializzazione per QPointer
?
Se non sai da dove cominciare o ciò che deve essere specializzata, così posso farlo anche io.
Soluzione
L'aggiunta di questo sovraccarico della funzione get_pointer
dovrebbe fare il trucco:
namespace boost {
template<typename T> T * get_pointer(QPointer<T> const& p)
{
return p;
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow