Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] TreeView move row one down causes app crash.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] TreeView move row one down causes app crash.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peer
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      peer
      wrote on last edited by
      #2

      Ok I find the answer.
      https://bugreports.qt-project.org/browse/QTBUG-6940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved