Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[solved]qmap::contains fails with segmentation fault



  • I don't know what's wrong with this code:

    @
    QMap<QString,QPersistentModelIndex> rows;
    int KeyAbstractModel::getRow(QString key){
    if(rows.contains(key))
    return rows[key].row();
    else return -1;
    }
    @

    it crashes whit segfault on rows.contains(key). I think the map contains something; for some reasons, debugger tells me <no such value> on rows. but also with an empty map, contains must work.



  • Is this your actual code?
    It very much sounds like you are trying to access not only an empty QMap, but a non-existant one.



  • yes. in fact I really think this is a qt bug, because the segfault signal comes during execution of qmap.h code. rows is not a null pointer, however. (it's not a pointer :D)

    edit: it seems I'm the only person that can solve a segfault problem sobstituting an object with a pointer to it.
    I modified rows into a QMap * and in constructor I wrote rows= new QMap<...>(); and now it works properly.
    really a strange thing.
    Thanks for making me have this idea, and thanks if someone has an hypothesis about this issue.


Log in to reply