• 2856阅读
  • 2回复

[讨论]Drag & Drop 过程中,源Item被释放(析构)程序出错 [复制链接]

上一主题 下一主题
离线jj200602
 

只看楼主 倒序阅读 楼主  发表于: 2018-01-02
如题。 现在拖动的Item 在放到Drop区前,动态地被析构了,必然会引起程序崩溃。

是我用法不对还是有什么方案可以解决的?
离线jj200602

只看该作者 1楼 发表于: 2018-01-02
import QtQuick 2.0
import QtQuick.Controls 1.3

Rectangle {
    id: container
    property int counter: 1
    width: 600; height: 600

    Timer{
        interval: 10000
        repeat: true
        running: true
        onTriggered: container.counter++;
    }

    Repeater{
        model: container.counter
        Rectangle {
            id: iddragblock
            width: 50; height: 50
            y: 54 * index
            x: 54 * index
            color: "red"
            Drag.active: idmousearea.drag.active
            Drag.dragType: Drag.Automatic
            MouseArea {
                id:idmousearea
                anchors.fill: parent
                drag.target: iddragblock
            }
        }
    }
}

试验代码如上。只要使用了Automatic, 触发Drag后保持按着不动,等源Item被释放后,松开鼠标就会出错。
离线maxlogo

只看该作者 2楼 发表于: 2018-01-03
When using Drag.Automatic you should also define mimeData and bind the active property to the active property of MouseArea : MouseArea::drag.active
个人博客:
简书:https://www.jianshu.com/u/14fa805306bd
CSDN:https://blog.csdn.net/qq10097355
思否:https://segmentfault.com/u/lowbees/articles
快速回复
限100 字节
 
上一个 下一个