Hello all,
I have attached a simple program to demonstrate an issue I am seeing with the sorting of model data in a table view. The code is below and should compile/run. I am using QT Creator 1.2.1 on Win Vista 32 Business.
THe error I am seeing is: for example:
if the data in row 4 column 0 is changed from 7000->3300, the order of the displayed data changes in the table view, however it only seems to sort based on the first character in the sequence... Can someone please explain how one would go about sorting by the entire integer in column 0 on data changed?

Thanks,
AlphaWolfXV

main.cpp
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "dialog.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. Dialog w;
  8. w.show();
  9. return a.exec();
  10. }
To copy to clipboard, switch view to plain text mode 
dialog.cpp
Qt Code:
  1. #include "dialog.h"
  2.  
  3. Dialog::Dialog(QWidget *parent)
  4. : QDialog(parent)
  5. {
  6. model = new QStandardItemModel(5,2);
  7. table = new QTableView(this);
  8. table->setModel(model);
  9. table->setSortingEnabled(true);
  10. table->sortByColumn(0);
  11.  
  12. addData2Model();
  13. QVBoxLayout *layout = new QVBoxLayout(this);
  14. layout->addWidget(table);
  15. setMinimumSize(300,300);
  16. setLayout(layout);
  17.  
  18. connect(model, SIGNAL(itemChanged(QStandardItem*)),this,SLOT(reorderTables(QStandardItem*)));
  19.  
  20. }
  21. void Dialog::reorderTables(QStandardItem *item)
  22. {
  23. table->sortByColumn(0, Qt::AscendingOrder);
  24. }
  25. void Dialog::addData2Model()
  26. {
  27. QList<int> rpm;
  28. QList<int> other;
  29. rpm<<600<<3000<<5000<<7000<<10000<<14000;
  30. other<<10<<10<<25<<25<<40<<40;
  31. for(unsigned char i = 0; i < 6; i++)
  32. {
  33. model->setItem(i,0,new QStandardItem(QString::number(rpm.at(i))));
  34. model->setItem(i,1,new QStandardItem(QString::number(other.at(i))));
  35. }
  36. qDebug()<<rpm<<other;
  37. }
  38. Dialog::~Dialog()
  39. {
  40.  
  41. }
To copy to clipboard, switch view to plain text mode 
dialog.h
Qt Code:
  1. #ifndef DIALOG_H
  2. #define DIALOG_H
  3.  
  4. #include <QtGui>
  5. #include <QDialog>
  6.  
  7. class Dialog : public QDialog
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. Dialog(QWidget *parent = 0);
  13. ~Dialog();
  14. public slots:
  15. void reorderTables(QStandardItem *item);
  16. private:
  17. QTableView *table;
  18. void addData2Model(void);
  19. };
  20.  
  21. #endif // DIALOG_H
To copy to clipboard, switch view to plain text mode 

testTableViewSort.pro
Qt Code:
  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2010-08-30T07:46:08
  4. #
  5. #-------------------------------------------------
  6.  
  7. TARGET = testTableViewSort
  8. TEMPLATE = app
  9.  
  10.  
  11. SOURCES += main.cpp\
  12. dialog.cpp
  13.  
  14. HEADERS += dialog.h
To copy to clipboard, switch view to plain text mode 

Thanks again!