I'm sorting a QTableWidget object with the sortItems() function.
myTable->sortItems(1, Qt::AscendingOrder);
QTableWidget myTable = new QTableWidget(rows, columns, this);
myTable->sortItems(1, Qt::AscendingOrder);
To copy to clipboard, switch view to plain text mode
Everything works fine but ascendingly rows are sorted like this:
1,.........................
10,......................
2,.......................
3.......................
etc.
In other words, this sort Items function thinks that 2>10 because 10 starts with a 1. How could I avoid this and make it consider number 10 as something that's bigger than 9 and smaller than 11.
This problem may have something to do with how I load myTable with integers. This is how it's done (do you see a problem with it):
myTable->setItem(y, x, item);
QTableWidgetItem *item = new QTableWidgetItem(QString::number(integer));
myTable->setItem(y, x, item);
To copy to clipboard, switch view to plain text mode
Later the sorted integers are extracted from myTable like this:
int val = a->text().toInt();
QTableWidgetItem *a = myTable->item(y,x);
int val = a->text().toInt();
To copy to clipboard, switch view to plain text mode
Thank you!
Bookmarks