[SOLVED] TreeView move row one down causes app crash.
-
I use Qt 5.3.2. I have tree like this:
@
QModelIndex()
|- Item 0
|- Item 1
|- Item 2
|- Item 3
|- Item 4
@Implemented virtual method:
@
bool ViewModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
const QModelIndex &destinationParent, int destinationChild)
{
if(sourceRow < 0 || sourceRow >= rowCount(sourceParent))
return false;
if(destinationChild < 0 || destinationChild >= rowCount(destinationParent))
return false;
if(sourceRow == destinationChild)
return false;beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild); endMoveRows(); return true;
}
@When I move item from 2 to 1 it works, but when I move item form 2 to 3 it crash becouse in qt source return false:
@
bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int start, int end, const QModelIndex &destinationParent, int destinationStart, Qt::Orientation orientation)
{
// Don't move the range within itself.
if (destinationParent == srcParent)
return !(destinationStart >= start && destinationStart <= end + 1);
@Example for moving item down:
@
bool ViewModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, QModelIndex &destinationParent, int destinationChild)//with values
bool ViewModel::moveRows(QModelIndex(), 2, 1, QModelIndex(), 3)
@In critical code where return false but need true:
@
return !(destinationStart >= start && destinationStart <= end + 1);//with values
return !( 3 >= 2 && 3 <= 2 + 1 );
return !( true && true);
@I did some mistake, or it's bug in qt 5.3.2?
-