I'm trying to learn Qt. I experienced some issues but generally I find the solution by googling. But this afternoon I had an issue with QMap and I don't understand the problem.
I've created a class File and I overrided the operator<
in order to be able to use it as key in QMap<File, bool>
. The issue is that when I try to initialize a QMap
by inserting entries the file map doesn't contain a duplicate entry in the sense of the implementation of the operator<
.
bool File::operator<(const File &file) const{
if(comparator == NAME){
if(this->getFileName() != file.getFileName()){
return this->getFileName() < file.getFileName();
}
return false;
}
return this->getFileHash() < file.getFileHash();
}
QMap
initialization:
for(File file: files){
//filesCheckStatus edclared in the header file QMap<File, bool> filesCheckStatus;
filesCheckStatus.insert(file, false);
}
In this example when comparator NAME
is used entries with the same name (QString
) are inserted only once.
In case I return false in all cases the final map contains only one entry (the first inserted).
Could someone explain this behavior?