PDA

View Full Version : wrong sort in qtableview



toem
26th June 2009, 07:56
Hello,

i am working with a QTableView under Qt4.5.1. I add headers and columns by programcode. After this i add my data in a loop from a stringfile.
I set tableview->setSortingEnabled(true)

Now my problem:

the original data are:

1. xxxx
2. xxxx
3. xxxx
4. xxxx
....
500. xxxx

after sort i had:

100: xxxx
101: xxxx
...
10: xxxx
110: xxxx
112: xxxx
...
11: xxxx
120: xxxx
etc.

How can i sort the columns right?

Lykurg
26th June 2009, 08:23
and here we go again. Please use our search engine first before posting! Catchwords "sort number" would have lead you to the solution!

Use QTableWidgetItem::setData() for setting an int value, then the sort will be correct.

toem
26th June 2009, 08:40
nice answer thx
but what happend if you have first numbers and after this letters in the same column?

Lykurg
26th June 2009, 11:30
nice answer thx
but what happend if you have first numbers and after this letters in the same column?

split the string in two parts number and text, add two hidden colums to your table and sort after them. Or you have to write your own sort algorithm, if it is too much to duplicate your data...