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. What to use in place of the obsoleted qsort?

What to use in place of the obsoleted qsort?

Scheduled Pinned Locked Moved Solved General and Desktop
qsort
5 Posts 3 Posters 1.0k 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.
  • mmikeinsantarosaM Offline
    mmikeinsantarosaM Offline
    mmikeinsantarosa
    wrote on last edited by
    #1

    I was looking for a way to sort a QVector and came across this forum thread that uses qsort. I was able to leverage this in my own code and it works just fine but... My qt.512 documentation says that qsort is obsoleted.

    What should I be using instead of qsort, now?

    qSort(foo.begin(), foo.end(), [](const marker& a, const marker& b) { return a.intensity < b.intensity; });
    1 Reply Last reply
    0
    • mmikeinsantarosaM Offline
      mmikeinsantarosaM Offline
      mmikeinsantarosa
      wrote on last edited by
      #5

      The Qt is pretty darn good.
      thanks again.

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

        Hi
        The docs suggest using std::sort instead.

        1 Reply Last reply
        5
        • mmikeinsantarosaM Offline
          mmikeinsantarosaM Offline
          mmikeinsantarosa
          wrote on last edited by
          #3

          OK, I just figured that since the original method used qSort and Qt usually provides a Qwhatever object/algorithm, there would be a newer qSuperSort or something like that. Reading further, I see there's a table of Q(algorithm)s that have been obsoleted and it includes their STL replacements.
          thanks

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

            In the deprecation warning you even get a hint about what's the replacement:
            https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qalgorithms.h?h=dev#n174

            "Use std::sort"

            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
            3
            • mmikeinsantarosaM Offline
              mmikeinsantarosaM Offline
              mmikeinsantarosa
              wrote on last edited by
              #5

              The Qt is pretty darn good.
              thanks again.

              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