Hi,
I'm trying to store QWeakPointers in a QSet with no success. The compiler first complained about QWeakPointer is lacking a qHash function. I Implemented a qHashFunction, the project compiled but I can't fetch data from the QSet (tried iterators). It only returns invalid QWeakPointers.
Basically I'm trying to do:
QSet<QWeakPointer<MyClass> > oneSet;
QSharedPointer<MyClass> > myClass(new MyClass);
oneSet.insert(oneSet.toWeakRef());
for (QSet<QWeakPointer<MyClass> >::iterator it = oneSet.begin(); it != oneSet.end(); it++)
{
// do stuff
}
//My qHash:
template<typename T>
uint qHash(const QWP<T> &p)
{
return qHash(p.data()); //use the pointer a a key.
}
QSet<QWeakPointer<MyClass> > oneSet;
QSharedPointer<MyClass> > myClass(new MyClass);
oneSet.insert(oneSet.toWeakRef());
for (QSet<QWeakPointer<MyClass> >::iterator it = oneSet.begin(); it != oneSet.end(); it++)
{
// do stuff
}
//My qHash:
template<typename T>
uint qHash(const QWP<T> &p)
{
return qHash(p.data()); //use the pointer a a key.
}
To copy to clipboard, switch view to plain text mode
Does anyone have a solution for this?
Bookmarks