How to use QSet as value in QMap?

477 views Asked by At

I'm using Qt and I want to declare following container:

QMap<QUrl , QSet<ClassSharedPtr> > map;

Here ClassSharedPtr is the boost shared ptr of class "Class".

typedef boost::shared_ptr<const Class> ClassPtr;

I'm getting following errors after adding header file #include :

error: no matching function for call to ‘qHash(const boost::shared_ptr<const Class>&)’
1

There are 1 answers

0
Meefte On

QSet's value data type must be an assignable data type. In addition, the type must provide operator==(), and there must also be a qHash() function in the type's namespace that returns a hash value for an argument of the values's type.

So, you should implement qHash() function for boost::shared_ptr<const Class>.

namespace boost {

uint qHash(const boost::shared_ptr<const Class> &key, uint seed = 0)
{
    const Class *ptr = key.get();
    return uint(ptr) ^ seed;
}

}