Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qtableview sorting issue
I am using qtableview to dispaly the data in my application . The data are stored in the QStandardItemModel . For sorting my data, i am using the following function
QStandardItemModel *grpModel; grpModel->sort(1,Qt::AscendingOrder);
Qtableview also have editing option , While editing the sorting will not work well, Please check the below image
sometimes i am having following error and application crashed
Please give the solution for this.
You know that you have to assign a valid pointer to grpModel? C++ basics.
QStandardItemModel *grpModel = new QStandardItemModel(); grpModel->sort(1,Qt::AscendingOrder);
i am done on the same way only.
i am done on the same way only
What do you mean? Do you mean you do it like I did and still have the crash?
Did you use debugger to get more information about the crash?
Do you have a stack trace after crash?
eswaramrth03 last edited by eswaramrth03
@jsulm i already assign the valid pointer as mention like you. If i debug my application , sometimes it will show the below message in the sort function line. If you press abort or retry it will lead to crash the application
. if it will not show the message means the wrong order will be displayed in the view as below.
i am converting Qstring to double for my application and store it in to list for my application calculation on backend.
If i debug the my application , it will show the below message
Please post the stack trace. How else should anybody know why it crashes?
nagesh last edited by
@eswaramrth03 first column is sorted in "string order", as data in the first column is QString.
How did you populate model data?
check for the answer in the following thread for the sorting.
VRonin last edited by
Basically always avoid using the constructors
QStandardItem(const QIcon &icon, const QString &text)and
QStandardItem(const QString &text)as most of the times they don't do what you want them to do
@VRonin i didn't use constructor as mention like you. In one case , I didn't get error as well as sort issue
If you give two digits instead of one digits , it will give proper result. Sample data
But in my application the user input should be either one digit or two digit.
VRonin last edited by
This is because you are storing numbers as stings so they get sorted in alphabetical order. Do not convert numbers to strings
JonB last edited by JonB