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. QMap that don't work properly

QMap that don't work properly

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 392 Views 2 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.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #1

    Hi, I've this code:

    QMap<uint8_t, uint8_t> OTable;
    
    OTable.insert( 1, '0');
    OTable.insert( 0, '1');
    OTable.insert( 5, '2');
    OTable.insert( 7, '3');
    OTable.insert( 9, '4');
    OTable.insert(13, '5');
    OTable.insert(15, '6');
    OTable.insert(17, '7');
    OTable.insert(19, '8');
    OTable.insert(21, '9');
    OTable.insert( 1, 'A');
    OTable.insert( 0, 'B');
    OTable.insert( 5, 'C');
    OTable.insert( 7, 'D');
    OTable.insert( 9, 'E');
    OTable.insert(13, 'F');
    OTable.insert(15, 'G');
    OTable.insert(17, 'H');
    OTable.insert(19, 'I');
    OTable.insert(21, 'J');
    OTable.insert( 2, 'K');
    OTable.insert( 4, 'L');
    OTable.insert(18, 'M');
    OTable.insert(20, 'N');
    OTable.insert(11, 'O');
    OTable.insert( 3, 'P');
    OTable.insert( 6, 'Q');
    OTable.insert( 8, 'R');
    OTable.insert(12, 'S');
    OTable.insert(14, 'T');
    OTable.insert(16, 'U');
    OTable.insert(10, 'V');
    OTable.insert(22, 'W');
    OTable.insert(25, 'X');
    OTable.insert(24, 'Y');
    OTable.insert(23, 'Z');
    
    
    qDebug() << OTable.key('A'); //Returns 1
    qDebug() << OTable.key('Z'); //Returns 23
    qDebug() << OTable.key('X'); //Returns 25
    qDebug() << OTable.key('0'); //Returns 0
    qDebug() << OTable.key('3'); //Returns 0
    qDebug() << OTable.key('9'); //Returns 0
    
    

    I don't understand why if I ask a key value of A-Z it works fine, but if I ask of 0-9 it returns always zero.
    I tried to pass ascii code directly, but the result is the same.
    I'm a bit confused.
    Do you have some ideas?
    Thanks.

    Stefano

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Dont you replace
      OTable.insert( 1, '0');
      with
      OTable.insert( 1, 'A');
      ? (same key)
      docs says
      "If there are multiple items with the key key, the most recently inserted item's value is replaced with value."

      1 Reply Last reply
      4
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Stefanoxjx said in QMap that don't work properly:

        I'm a bit confused.

        You have a map, not a multimap so

        OTable.insert( 1, 'A');

        overwrites

        OTable.insert( 1, '0');

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        5
        • S Offline
          S Offline
          Stefanoxjx
          wrote on last edited by
          #4

          Many thanks for clarification.
          I understand the problem :)

          Stefano

          1 Reply Last reply
          1

          • Login

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