qt6qmap

How to QMap()::begin() + int offset


I have function in my filemodel which returns actual file name in specific position.

...
QMap<QString, QFileInfo> fileInfoMap_;
...

QString MFileModel::fileAt(int offset) const
{
   return (fileInfoMap_.begin() + offset).key();
}
...

Problem is, that this feature stop working in QT6. How can i repair it? I looking for documentation, without success.

QMap.begin() returns QMap::const_iterator. There is no option to use "+ int".

Build retur error: ...mfilemodel.cpp:276: error: invalid operands to binary expression ('QMap<QString, QFileInfo>::const_iterator' and 'int')


Solution

  • This solved my problem. Maybe siple way exists. But this works too.

    QString MFileModel::fileAt(int offset) const
    {
    
        QMap<QString, QFileInfo>::const_iterator ci = fileInfoMap_.begin();
    
        for (int i=0; i<offset; i++)
        {
              ci = ci.operator++();
        }
    
        //return (fileInfoMap_.begin() + offset).key();
        return ci.key();
    }