0

Before I embark into using this datatype and as I am a beginner in Qt, is it possible to use QGraphicsItem as key of QHash? It seems legal to declare something like:

QHash<QGraphicsItem*, someType> hashName;

So I guess it is something allowed.

Thanks.

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Francesco
  • 481
  • 2
  • 4
  • 16

1 Answers1

0

Yes. But I'd use QMap<QGraphicsItem*, someType>, that doesn't make much difference, though. Also, you can inherit QGraphicsItem to attach data to items.

mugiseyebrows
  • 4,138
  • 1
  • 14
  • 15
  • There is no point in using `QMap` here: lookup by key is slower in `QMap`, and ordering by pointer doesn't make any sense. Also attaching data to items is possible through `QGraphicsItem::setData` without subclassing `QGraphicsItem`. – Pavel Strakhov Mar 24 '14 at 16:09
  • I thought using hash requires calculating hash of key on accessing, iterating and inserting values (in `QHash` implementation, behind the scenes). Or hashing int/pointer optimized somehow? – mugiseyebrows Mar 24 '14 at 20:05
  • Hashing pointers is trivial and is performed in Qt as `reinterpret_cast(key) ^ seed`. – Pavel Strakhov Mar 24 '14 at 23:14