I am trying to sort values numerically instead of alphabetically in my QTreeWidget. Right now It's comparing as two strings, what I need is for it to compare as two integers.
What I have so far:
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QSql>
//more include...
#include <QTreeWidget>
extern QSqlDatabase db;
//more extern...
namespace Ui {
class mainwindow;
class TreeWidgetItem;
}
class TreeWidgetItem : public QTreeWidgetItem
{
Q_OBJECT
public:
TreeWidgetItem(QTreeWidget *tree) : QTreeWidgetItem(tree) {}
TreeWidgetItem(QTreeWidget * parent, const QStringList & strings)
: QTreeWidgetItem (parent,strings) {}
bool operator< (const QTreeWidgetItem &other) const
{
int column = treeWidget()->sortColumn();
return text(column).toInt() < other.text(column).toInt();
}
};
class mainwindow : public QMainWindow
{
Q_OBJECT
public:
//...
but it doesn't work, any idea what else i need to do? Or am I completely off?