So, I have simple code
QMap<QColor, int> colors;
for(int w = 0; w < image.width(); ++w)
for (int h = 0; h < image.height(); ++h)
colors[QColor::fromRgb(image.pixel(w,h))]++;
The error message is
no match for 'operator<' (operand types are 'const QColor' and 'const QColor').
So, qMapLessThanKey is trying unsuccessfully to instantiate comparer of two colors and it's impossible.
Question is: Is it possible to store QColor in a QMap as key as value and not by reference?
Just curious. I know how to write what I want in other way. But it looks for me strange that there is any exceptions in QT on what I can store in map or cannot.
No, because
QColor
doesn't provideoperator<
, which is required byQMap
'sKey
type:An option would be to define
operator<
forQColor
yourself, but I wouldn't advise it, as I'm not sure it's supposed to be defined.I would recommend just to use
std::map
with a custom comparator (the third template argument) along the lines of: