[Qt-interest] QSharedPointer and QMap/QHash

Rudenko Eugene erule.biz at gmail.com
Fri Feb 12 14:25:20 CET 2010


Hello.
I'm trying to use QMap/QHash with QSharedPointer with no success.

For example, such code:
===============================
class MyClass : QObject {
Q_OBJECT
..........
QMap< QSharedPointer<MyClass>, int > mm;  //or QHash
}


........
QSharedPointer<MyClass> a = b.getPointer();
mm.insert(a,0);

===============================
I have got error:
in case of use QHash:
no matching function to call to 'qHash(const QSharedPointer<MyClass> & )'
candidates: ..........


in case of use QMap:
no match for 'operator<' in 'key1 < key2'
candidates are ........


As I can see, there are no overloaded operators "<" and "qHash" for QSharedPointer, to redirect it to containing object.
As I can understand, QSharedPointer is not suitable to use with QMap and QHash, Is I right?
How can I use container classes with smart pointer classes ?


With best regards, Eugene Rudenko.








More information about the Qt-interest-old mailing list