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. Sort QList in another thread
Qt 6.11 is out! See what's new in the release blog

Sort QList in another thread

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.2k 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.
  • R Offline
    R Offline
    ranger0
    wrote on last edited by
    #1

    Hi guys,

    I'd like to sort a QList in another thread.

    My first try was using QtConcurrent::run() function, like this:

    @
    QFuture<void> classificando = QtConcurrent::run(qStableSort,classificar);
    @

    I got:

    ....\complementos\matriz.cpp: In member function 'void matriz::classifica(int, Qt::SortOrder)':
    ....\complementos\matriz.cpp:55: error: no matching function for call to 'run(<unresolved overloaded function type>, QList<QPair<QString, unsigned int> >&)'
    mingw32-make.exe[1]: Leaving directory `C:/Users/rangel/Documents/Programas/Laboratorio/Principal/LIMS/cadastro/cliente-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug'
    mingw32-make.exe[1]: *** [debug/matriz.o] Error 1
    mingw32-make.exe: *** [debug] Error 2
    09:10:09: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project cliente (target: Desktop)
    When executing build step 'Make'

    Does anyone could help me?

    Thanks.

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

      Hi,

      the compiler say you it doesn't resolve first parameter of QtConcurrent::run().
      Are you sure qStableSort header <QtAlgorithm> is included?

      qStableSort accept as parameter two iterators and not collection.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ranger0
        wrote on last edited by
        #3

        Hi mcosta,

        Yes. I'm sure I included QtAlgorithm.

        I use this function with a collection and it works in GUI thread.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,
          If i'm not mistaken, qStableSort is an inline template function and if IIRCC, using a template function is not directly supported with run (But I may be wrong).

          However, using a wrapper function, you can achieve what you want:

          @
          #include <QtConcurrentRun>

          typedef QList<QPair<QString, unsigned int> > MyContainer; // Just to have simpler code

          void stableSortWrapper(MyContainer &list) {
          qStableSort(list);
          }

          void MyStartingFunction()
          {
          MyContainer classificar;
          QFuture<void> classificando = QtConcurrent::run(stableSortWrapper, classificar);
          }
          @

          Hope it helps

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

          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