Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]qmap::contains fails with segmentation fault
Forum Updated to NodeBB v4.3 + New Features

[solved]qmap::contains fails with segmentation fault

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    p91paul
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p91paul
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved