-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.1.1
-
None
-
Windows XP Pro SP3, QtCreator 2.8.1, Qt 5.1.1 MSVC 2010 32 bit
I'm developping a multi-thread application.
At loading step, a lot of updates are done on a QStandardItemModel.
I have a class called CTX that inherits QStandardItemModel
This class has a member function calld itemFromX used to get QStandardItem pointeur in model according to the X value of the item.
This X value is stored in data list of each item.
So my function looks like :
QStandardItem *CTX::itemFromX(int x){ QModelIndex idx; QStandardItem *item=NULL; QMutexLocker l(M_MUTEX); // prevent from multi-thread access int xfound=false; int row=0; int rowcount=this->rowCount(); while(xfound != x && row < rowcount) { //looking in all item in first column only idx=this->index(row,0); if(idx.isValid()) { QVariant valX=idx.data(Qt::UserRole+1); //=> this line above causes sometimes crash at loadind step with // error "index out of range in QVector<int> ... qvector.h //... if(valX.isValid())xfound=valX.toInt(); row++; } } return item; }
So, I can't be sure that data(QtUserRole+1) has been initialized before passing here and so, before trying to access to it.
Nothing is said when trying to access to data role that doesn't exists for QModelIndex, but for QStandardItem::data, it is said that it returns a non-valid QVariant, so with no error.
It could interesting to check if the behaviour is really the same. That could explain why this line causes a crash with "index out of range" when index was not initialized. If both uses the same code, here we have a bug I think.
[Suggestion]
So, I think both should have the same behaviour, and if it is, both documentations should be the same.
Good luck