I have a qtableview
, some of its columns' data are like:
[20,1647.8,2101.2,1911.6, ... ,-1.6915] It's basically an array of float values separated by comma and wrapped up by square brackets. But the first one is an integer telling how many values in this array.
I need to get every value separated by ",", so first I use QModelIndex
to get the cell's content, then I convert the data type from QVariant
to QString
, followed by other processing:
QModelIndex index = myTable->model()->index(row,col,QModelIndex());
QVariant arrayQVar = myTable->model()->data(index);
QString arrayStr = arrayQVar.toString();
//.... Other processing follows, the above repeated many times
Sometimes, I would say sth like 1/10000 times arrayStr
is different from arrayQVar
For example,
When I print out arrayQVar
I got sth like:
QVariant(QString, "[20,1647.8,2101.2,1911.6,756.84...]")
But if I print out arrayStr
, I got sth like:
[20,-4388.4,-6596.3,-6368.5,...]
All values are different except the first one.
I am using Qt 5.15.10 MinGW 64-bit, the above codes run in a different thread other than GUI thread.
This happens randomly, i.e. A random cell in the table can have this issue, and it doesn't always happen. I think QVariant to QString conversion is a very basic conversion...right? maybe I need to change the first value to 20.0? Since the difference takes place after the first number...