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. Nested QMap with a QHash and fetching values inside the QHash?
Forum Updated to NodeBB v4.3 + New Features

Nested QMap with a QHash and fetching values inside the QHash?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 503 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.
  • C Offline
    C Offline
    Calicoder
    wrote on last edited by
    #1

    Howdy folks, hope your 2022 is going well so far. Another day trying to train myself on C++ and QT. I've been playing around with containers and noticed something odd with using QMaps. I can only fetch the outer most keys and never anything inside that.
    For example, say I have this setup of a customer ID dataset:

    QMap(("customerIdData", QVariant(QVariantHash, QHash(("Mike", QVariant(double, 0439.7))))))
    

    Using the QMap.value("customerIdData") works well but this QMap.value("Mike") only shows the default 0 value. Is this possible to access that inner QHash double value?

    Appreciate the help as always.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please provide some real code on how you fill and later try to read your structure.

      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
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Beside the code, you shall start by doing it in steps:

        • Get the variant from the map
        • Convert the variant to a hash
        • Extract the value you want from the hash

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        C 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Beside the code, you shall start by doing it in steps:

          • Get the variant from the map
          • Convert the variant to a hash
          • Extract the value you want from the hash
          C Offline
          C Offline
          Calicoder
          wrote on last edited by
          #4

          @SGaist said in Nested QMap with a QHash and fetching values inside the QHash?:

          Hi,

          Beside the code, you shall start by doing it in steps:

          • Get the variant from the map
          • Convert the variant to a hash
          • Extract the value you want from the hash

          Perfect, thanks guys! This worked

          QMap.first().toHash().value("Mike").toDouble()
          
          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