Crash on Mouse move event in modified TreeView



  • Hi,
    I have patched the Qt Quick's Treeview to allow dragging of the items. Here is the diff of TreeView and my patched version

    diff --git a/TreeView.qml b/PatchedTreeView.qml
    index aa21acc..fdef3e0 100644
    --- a/PatchedTreeView.qml
    +++ b/PatchedTreeView.qml
    @@ -52,6 +52,9 @@ BasicTableView {
         readonly property var currentIndex: modelAdaptor.mapRowToModelIndex(__currentRow)
         property ItemSelectionModel selection: null
     
    +    property int draggedRow: -1
    +    property int selectedRow: -1
    +
         signal activated(var index)
         signal clicked(var index)
         signal doubleClicked(var index)
    @@ -86,6 +89,10 @@ BasicTableView {
             return modelAdaptor.mapRowToModelIndex(__listView.indexAt(obj.x, obj.y))
         }
     
    +    function setDragTarget(itm) {
    +        mouseArea.drag.target = itm
    +    }
    +
         style: Settings.styleComponent(Settings.style, "TreeViewStyle.qml", root)
     
         // Internal stuff. Do not look
    @@ -274,6 +284,37 @@ BasicTableView {
                 pressedColumn = -1
                 autoScroll = 0
                 selectOnRelease = false
    +
    +            if(drag.active && false){ // the if condition is disabled with the false
    +                var draggedIndex = modelAdaptor.mapRowToModelIndex(draggedRow)
    +                root.draggedRow = -1
    +                drag.target = null
                     ...                
    +            }
             }
     
             onPositionChanged: {
    

    As you can see I am not changing a lot, I have already commented out most of my changes. The problem is the app crashes from time to time, when selecting items in the tree. Here is the stack trace

    1  QQuickItem::parentItem() const                                    0x10030f548    
    2  QQuickMouseArea::mouseMoveEvent(QMouseEvent *)                                         0x1003a19fd    
    3  QQuickItem::event(QEvent *)                                                            0x10031dd31    
    4  QApplicationPrivate::notify_helper(QObject *, QEvent *)                                0x101965edd    
    5  QApplication::notify(QObject *, QEvent *)                                              0x101968822    
    6  QCoreApplication::notifyInternal2(QObject *, QEvent *)                                 0x100e67aa4    
    7  QQuickWindow::sendEvent(QQuickItem *, QEvent *)                                        0x1003296c5    
    8  QQuickWindowPrivate::deliverMouseEvent(QMouseEvent *)                                  0x10032e79a    
    9  QQuickWindow::mouseMoveEvent(QMouseEvent *)                                            0x10032f62e    
    10 QWindow::event(QEvent *)                                                               0x1012e2f15    
    11 QQuickWindow::event(QEvent *)                                                          0x10032cc80    
    12 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                0x101965edd    
    13 QApplication::notify(QObject *, QEvent *)                                              0x101968822    
    14 QCoreApplication::notifyInternal2(QObject *, QEvent *)                                 0x100e67aa4    
    15 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *) 0x1012d488a    
    16 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)  0x1012be06b    
    17 QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void *)                       0x104367631    
    18 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__                             0x7fff959c17e1 
    19 __CFRunLoopDoSources0                                                                  0x7fff959a0f1c 
    20 __CFRunLoopRun                                                                         0x7fff959a043f 
    21 CFRunLoopRunSpecific                                                                   0x7fff9599fe38 
    22 RunCurrentEventLoopInMode                                                              0x7fff831ce935 
    23 ReceiveNextEventCommon                                                                 0x7fff831ce677 
    24 _BlockUntilNextEventMatchingListInModeWithFilter                                       0x7fff831ce5af 
    25 _DPSNextEvent                                                                          0x7fff85e6edf6 
    26 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:]                 0x7fff85e6e226 
    27 -[NSApplication run]                                                                   0x7fff85e62d80 
    28 QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)            0x10436653f    
    29 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)                                0x100e63eb1    
    30 QCoreApplication::exec()                                                               0x100e68115    
    31 main                                                                                   main.cpp 65 0x100006839    
    32 start                                                                                  0x7fff988195ad
    

    I have already tried to make tree items draggable by adding a mouse area to the item delegate but that prevents the tree from receiving onPressed events which disables the selection.
    That would be great if someone could help me finding the cause or guide me how to make Treeview items draggable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.