查看完整版本: [-- Drag & Drop 过程中,源Item被释放(析构)程序出错 --]

QTCN开发网 -> Qt QML开发 -> Drag & Drop 过程中,源Item被释放(析构)程序出错 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

jj200602 2018-01-02 22:32

Drag & Drop 过程中,源Item被释放(析构)程序出错

如题。 现在拖动的Item 在放到Drop区前,动态地被析构了,必然会引起程序崩溃。

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

jj200602 2018-01-02 22:40
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 2018-01-03 22:51
When using Drag.Automatic you should also define mimeData and bind the active property to the active property of MouseArea : MouseArea::drag.active


查看完整版本: [-- Drag & Drop 过程中,源Item被释放(析构)程序出错 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled