Problem with qSort of QList<CustomType>
-
wrote on 30 Nov 2016, 15:53 last edited by Ivan Netskin 12 Jan 2016, 08:16
Hello, trying to sort QList <MyType> list. Doing this:
qSort(list.begin(),list.end(),sortFunc); .... bool sortFunc(const MyType1& mt1, const MyType2& mt2){ return false; }
So the first line of code above produce error:
error: C2064: term does not evaluate to a function taking 2 arguments.
What's the problem guys? I've already successfully sorted QStringList that way btw. Thanks in advance! -
wrote on 30 Nov 2016, 16:06 last edited by
Hi,
your sort function looks ok. Please make sure, though, that it is not a member function of some class and you should declare it before you call qSort.
-Michael. -
wrote on 30 Nov 2016, 20:47 last edited by
One small thing to check: are you defining / declaring the
sortFunc
function before or after theqSort
invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving thesortFunc
function definition above theqSort
call in the file.Cheers.
-
Hello, trying to sort QList <MyType> list. Doing this:
qSort(list.begin(),list.end(),sortFunc); .... bool sortFunc(const MyType1& mt1, const MyType2& mt2){ return false; }
So the first line of code above produce error:
error: C2064: term does not evaluate to a function taking 2 arguments.
What's the problem guys? I've already successfully sorted QStringList that way btw. Thanks in advance!Let's see ... MSDN also provides comprehensive examples, by the way ...
-
wrote on 1 Dec 2016, 08:14 last edited by
Big thanks guys, next time i'll google better! Making the function static solved my problem. Thanks again for help guys!
-
One small thing to check: are you defining / declaring the
sortFunc
function before or after theqSort
invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving thesortFunc
function definition above theqSort
call in the file.Cheers.
wrote on 1 Dec 2016, 08:55 last edited by@Paul-Colby said in Problem with qSort of QList<CustomType>:
One small thing to check: are you defining / declaring the
sortFunc
function before or after theqSort
invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving thesortFunc
function definition above theqSort
call in the file.Cheers.
You were absolutely right. Thanks!
1/6