Sort QList in another thread



  • 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.



  • 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.



  • Hi mcosta,

    Yes. I'm sure I included QtAlgorithm.

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


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.