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 -> what does .contains() compare?
Forum Updated to NodeBB v4.3 + New Features

QMap -> what does .contains() compare?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 666 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.
  • Flaming MoeF Offline
    Flaming MoeF Offline
    Flaming Moe
    wrote on last edited by
    #1

    Hello there,

    running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
    The documentation says
    "Returns true if the map contains an item with key key; otherwise returns false."
    For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.

    ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
    -> Is that correct? And if so, where do I find that information?

    Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?

    A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

    sierdzioS Christian EhrlicherC 2 Replies Last reply
    0
    • Flaming MoeF Flaming Moe

      Hello there,

      running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
      The documentation says
      "Returns true if the map contains an item with key key; otherwise returns false."
      For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.

      ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
      -> Is that correct? And if so, where do I find that information?

      Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Flaming-Moe said in QMap -> what does .contains() compare?:

      Hello there,

      running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
      The documentation says
      "Returns true if the map contains an item with key key; otherwise returns false."
      For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.

      Hash is generated in QHash, not in QMap.

      ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
      -> Is that correct? And if so, where do I find that information?

      Yes.

      Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?

      The one which overloads the comparison: bool opearator==(const QTime &other) const.

      (Z(:^

      1 Reply Last reply
      2
      • Flaming MoeF Flaming Moe

        Hello there,

        running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
        The documentation says
        "Returns true if the map contains an item with key key; otherwise returns false."
        For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.

        ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
        -> Is that correct? And if so, where do I find that information?

        Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?

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

        @Flaming-Moe said in QMap -> what does .contains() compare?:

        "Returns true if the map contains an item with key key; otherwise returns false."
        For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.

        Comparing means operator==(), or do you compare your stuff with something else?

        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
        • Flaming MoeF Offline
          Flaming MoeF Offline
          Flaming Moe
          wrote on last edited by
          #4

          Okay I was not aware, that == is the compare operator

          since others are also overloaded

          bool	operator<=(QTime lhs, QTime rhs)
          bool	operator==(QTime lhs, QTime rhs)
          bool	operator>(QTime lhs, QTime rhs)
          bool	operator>=(QTime lhs, QTime rhs)
          

          A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

          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