PDA

View Full Version : QDir - Entrylist, sort



bismitapadhy
27th January 2010, 11:45
I have file name like

test1.tcl
test2.tcl
test3.tcl
test10.tcl
test100.tcl

when i am taking the ertrylist it is giviving in the order as follows:

test1.tcl
test10.tcl
test100.tcl
test2.tcl
test3.tcl

but i want in the order of
test1.tcl
test2.tcl
test3.tcl
test10.tcl
test100.tcl

I used Qdir::unsort , but it not givng the order of entrylist as i want. How can i do this.

aamer4yu
27th January 2010, 12:06
You can override QDirModel::sort and provide your own sorting

bismitapadhy
27th January 2010, 12:45
I am a beginner in Qt,
can you please tell me how can i override Qdir::sort ?
Please give one example.

squidge
27th January 2010, 14:49
The problem is that you are comparing text strings, and so test1, test10 & test100 will always be less than test2. What you need to do is seperate the text and numeric portions and do your own custom sort.

To override QDir::Sort, just subclass QDir and override the default implementation of sort by writing your own.

bismitapadhy
28th January 2010, 06:14
Can you please send me the algorithem for separating numeric and text and sorting them as 1, 2, 3,10.
If i am using sort algorithem then it is sorting as 1,10,2,3.
Please help me.

bismitapadhy
28th January 2010, 06:27
I separated numeric and text part, can you please tell how can i do sort that it will arrange as
1
2
3
10