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. Purpose of STL-style parts of collection classes
Qt 6.11 is out! See what's new in the release blog

Purpose of STL-style parts of collection classes

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • I Offline
    I Offline
    ivan
    wrote on last edited by ivan
    #1

    Most people (myself included) tend to praise Qt because its API is much more pleasant than STL. But Qt does provide STL-style members and iterators in its collection classes.

    The main reason I see for this is to make them work with generic algorithms (from STL, or custom ones). But this doesn't work as it should. Qt has some quite important incompabilities.

    Two of them I have encountered just wanting to write a proper lambda-enabled for_each for associative containers are:

    • STL's cbegin is called constBegin (and the same for cend)
    • QMap/QHash iterators have nothing in common to STL's iterators
      • STL's iterator is a 'pointer' to a pair, Qt's is a 'pointer' to a value

      • Qt's pointer has key and value methods, while in STL you use first and second members of the pair

        // Qt:
        it.key(), it.value()
        // STL:
        it->first, it->second

    This means that more advanced custom generic algorithms will fail either on Qt or STL. Or, you need to do a lot of template magic just to differentiate those two and provide the same API for both.

    Any thoughts on this? Is this something that should be fixed, forgotten, ... or does STL-style API in Qt serves some strange purpose I just don't see.

    Ivan Čukić | ivan.cukic(at)kde.org | KDE e.V.
    Qt Ambassador (from the old Nokia days)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      miroslav
      wrote on last edited by
      #2

      I was wondering about that, too.

      Mirko Boehm | mirko@kde.org | KDE e.V.
      FSFE Fellow
      Qt Certified Specialist

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ivan
        wrote on last edited by
        #3

        I've posted a bug report which I guess will go without comments :/
        https://bugreports.qt-project.org/browse/QTBUG-25997

        I'd even work on this if somebody said 'hmh, that should be fixed'.

        The issue is that it could break api for the case of operator->, the rest i think could be tricked into proper behavior.

        Ivan Čukić | ivan.cukic(at)kde.org | KDE e.V.
        Qt Ambassador (from the old Nokia days)

        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