4

I am using QMap and I have pointers to the object as keys of the map. Using std::map I would write a comparator for pointers and declare my map as follow

std::map<Key*, Value, ComparatorOfPointers<Key> >

How I have to do with QMap? I cannot find in Qt documentation which template parameters are acceptable.

NG_
  • 6,895
  • 7
  • 45
  • 67
user14416
  • 2,922
  • 5
  • 40
  • 67
  • possible duplicate of [Does QMap support custom comparator functions?](http://stackoverflow.com/questions/17463889/does-qmap-support-custom-comparator-functions) – sashoalm Feb 23 '15 at 14:22

1 Answers1

4

QMap (unlike std::map) always uses operator< to compare the keys. So you will have to wrap the pointer in a class and define a suitable operator< for that class.

Johan Råde
  • 20,480
  • 21
  • 73
  • 110