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.
-
@eswaramrth03 said in Qtableview sorting issue:
QStandardItemModel *grpModel;
grpModel->sort(1,Qt::AscendingOrder);You know that you have to assign a valid pointer to grpModel? C++ basics.
QStandardItemModel *grpModel = new QStandardItemModel(); grpModel->sort(1,Qt::AscendingOrder);
-
@eswaramrth03 said in Qtableview sorting issue:
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? -
@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.
-
@eswaramrth03 said in Qtableview sorting issue:
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?
-
@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.
https://forum.qt.io/topic/115420/sorting-numerical-values-in-qtableview-with-widgets -
@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
00
05
09
11
20
instead of
0
5
9
11
20But in my application the user input should be either one digit or two digit.
-
@eswaramrth03
As @VRonin has said. Please read the link @nagesh gave you and follow thatQStandardItem::setData()
pattern to correctly store numbers.