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: find exact or lower
Forum Update on Monday, May 27th 2025

QMap: find exact or lower

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 433 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.
  • D Offline
    D Offline
    dextermagnific
    wrote on last edited by
    #1

    Hi All,

    Do you know if there is QMap function to search for exact or lower value ? I'm aware of QMap::lower_bound() but this returns exact or upper.

    Also, in terms of C++, if I do:

    auto it = mymap.lower_bound(val);
    

    Do you know which implementation is chosen ? it is the const or the non const one ?
    If it is the non const one, what are the consequences (is the whole list duplicated ? I see a detach() in the code).

    Thanks

    Christian EhrlicherC 1 Reply Last reply
    0
    • D dextermagnific

      Hi All,

      Do you know if there is QMap function to search for exact or lower value ? I'm aware of QMap::lower_bound() but this returns exact or upper.

      Also, in terms of C++, if I do:

      auto it = mymap.lower_bound(val);
      

      Do you know which implementation is chosen ? it is the const or the non const one ?
      If it is the non const one, what are the consequences (is the whole list duplicated ? I see a detach() in the code).

      Thanks

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @dextermagnific said in QMap: find exact or lower:

      Do you know which implementation is chosen ? it is the const or the non const one ?

      If mymap is const then the const version, if not then the non-const version.

      If it is the non const one, what are the consequences (is the whole list duplicated ? I see a detach() in the code).

      It's only duplicated when it's needed (e.g. the ref count is greater than one).

      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
      • D Offline
        D Offline
        dextermagnific
        wrote on last edited by
        #3

        Thanks a lot

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @dextermagnific said in QMap: find exact or lower:

          Do you know if there is QMap function to search for exact or lower value ? I'm aware of QMap::lower_bound() but this returns exact or upper.

          Can you take the result of QMap::lower_bound() and, with appropriate checks, move the iterator to the previous position?

          1 Reply Last reply
          1
          • D Offline
            D Offline
            dextermagnific
            wrote on last edited by
            #5

            Yes I was planning to do it like this. Just asked to be sure that there was no way to get it (and also rationale behind this: in std lib there is also lower_bound() but not what I'm looking for. So had some doubt about doing something wrong).

            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