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. Unable to access elements in a nested QMap

Unable to access elements in a nested QMap

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.2k Views
  • 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.
  • W Offline
    W Offline
    wolf.
    wrote on last edited by
    #1

    I am unable to do the simplest of access to a nested QMap

    I have no problem compiling it:
    @QMap<QString, QMap<int, int> > nestedMap;@

    But I can't even do simple checks on it:
    @if(!nestedMap.contains(someKey)) { // <-- segfault at runtime
    // Start adding stuff
    }@

    I partially got around this problem by first loading up the inner QMap and then inserting it into the nested QMap with its respective key.
    @for(i=0; i<rows; i++) {

    QString curkey  = data[rows][1];             // keys are sorted
    int     subkey  = data[rows][2].toInt(&ok);
    int     subval  = data[rows][3].toInt(&ok);
    
    if(oldkey.compare(curkey)) {                 // Changed Keys?
        nestedMap.insert(oldkey, regularMap);    // assemble nestedMap
        dp.clear();
        oldkey = curkey;
    }
    
    if(!dp.contains(subkey)){
        dp[subkey] = subval;
    }
    

    }@

    (The example above needed to be somewhat contrived to the end of isolating the relavant section of code. The logic is effectively the same.)

    But then I'm back to not being able to use the data.
    Testing fails:
    @if(!nestedKey.contains(possibleKey)) // segfault at runtime@

    Extraction fails:
    @regularQMap = nestedMap.value(knownKey); // segfault at runtime@

    Hopefully I'm just failing to see some basic principle of this container, but if anyone has any ideas I'd love to hear them.

    Thank you

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There is nothing wrong with nesting QMap.
      It would be my guess there must be something else wrong with your code just manifesting this way.
      Maybe you've got a bad memory write (out of bound etc.) that just happens to hit something in that map and messes it up.
      Maybe it's a bad build. Have you tried clearing and rebuilding your project?
      Maybe you're trying to access a map via an invalid pointer etc.

      Hard to say but the declaration looks ok.

      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