PDA

View Full Version : Some trouble with QList<> and qsort



cit
25th July 2014, 21:46
I hope somebody can help. I try to sort, but I get an error. :-(((





class FileEntry
{

public:
QString name;
QString absolutePath;
QString relativePath;
double size;
QString typ;
QDateTime createDate;
bool selected;
int index;


FileEntry(QString pName, QString pAbsolutePath,QString pRelativePath,double pSize,QString pTyp,QDateTime pCreateDate,bool pSelected,int pIndex)
{
name = pName;
absolutePath =pAbsolutePath;
relativePath=pRelativePath;
size=pSize;
typ=pTyp;
createDate=pCreateDate;
selected=pSelected;
index = pIndex;
}

};



bool lessSize(const FileEntry& a, const FileEntry& b)
{
return a.size < b.size;
}




void DoSelection()
{
QList<FileEntry> tmpList;

tmpList.append(FileEntry("A","A","A",2.2,"A",QDateTime(),false,1));
tmpList.append(FileEntry("A","A","A",2.2,"A",QDateTime(),false,1));

qsort(tmpList.begin(),tmpList.end(),lessSize);
}





I get these error:
error: cannot convert 'QList<FileEntry>::iterator' to 'void*' for argument '1' to 'void qsort(void*, size_t, size_t, __compar_fn_t)'
qsort(tmpList.begin(),tmpList.end(),lessSize);

Thx.Cit

I tried the way from this post.....

http://www.qtcentre.org/threads/9485-Sorting-using-qSort%28%29-if-QList-contains-POINTERS

sulliwk06
25th July 2014, 21:54
having never used qsort before, all I can say is that its looking at the wrong footprint of qsort. What version of Qt are you running?

stampede
25th July 2014, 22:20
this

qsort(tmpList.begin(),tmpList.end(),lessSize);
tries to call C function

qsort(void* ptr, size_t count, size_t size_in_bytes, int (*compare_function)(const void*,const void*))
signature obviously does not match arguments provided.
Probably this is what you want


qSort(tmpList.begin(),tmpList.end(),lessSize);

cit
25th July 2014, 23:04
I go back to the simple basic's std:sort() instead of qsort()...... and it works from the beginning-