更改Text.text时QML崩溃

时间:2016-07-28 13:53:12

标签: qml

我是QML的新手,所以我尝试了几件事。大多数工作,但当我尝试更改text - 元素时,程序总是崩溃。

E.g:

import QtQuick 2.3
import QtQuick.Window 2.2

Window {
    id: root
    visible: true
    width: 640
    height: 480

    Text {
        id: mytex
        // text: area.mouseX + " / " + area.mouseY
    }

    MouseArea {
        id: area
        anchors.fill: parent
        // hoverEnabled: true
        // onClicked: { mytex.text = mouseX + " / " + mouseY }
        onMouseXChanged: { mytex.text = mouseX + " / " + mouseY }
    }
}

我想要的只是一个文本,显示当前的鼠标坐标(无论何时我点击或更好,只要我悬停MouseArea

我在Windows机器上使用QtQuick 2.3和mingw。

编辑: 我尝试了以下代码:

import QtQuick 2.3
import QtQuick.Window 2.2

Window {
    id: root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    property int count: 0
    property string countstr: count.toString()

    MouseArea {
        anchors.fill: parent
        onClicked: {
            count += 1
            console.log(countstr)
        }
    }

    Text {
        text: qsTr(countstr + ' times clicked')
        anchors.centerIn: parent
    }
}

在我的Windows和Linux机器上使用QTcreator。 在Linux上,它运行完美。 因此,我得出结论,它应该工作(并且最终可以阻止我的代码中出现故障的令人沮丧的搜索)但我仍然不知道为什么它在Windows上不起作用。

在调试模式下,它是sais(对于后面的代码):

qrc:/main.qml:20:5: QML Text: Binding loop detected for property "text"
qrc:/main.qml:20:5: QML Text: Binding loop detected for property "text"
qrc:/main.qml:20:5: QML Text: Binding loop detected for property "text"
qrc:/main.qml:20:5: QML Text: Binding loop detected for property "text"
QQmlExpression: Expression qrc:/main.qml:21:15 depends on non-NOTIFYable properties:

...

2 个答案:

答案 0 :(得分:0)

即使启用了悬停,似乎mouseXmouseY也不会更新。 qmlscene中的一个简短测试适用于您在底部找到的代码。希望它有所帮助。

import QtQuick 2.3
import QtQuick.Window 2.2

Item {
    id: root
    visible: true
    width: 640
    height: 480

    Text {
        id: mytex
    }

    MouseArea {
        id: area
        anchors.fill: parent
        hoverEnabled: true
        onPositionChanged: {
            mytex.text = mouseX + " / " + mouseY
        }
    }
}

答案 1 :(得分:0)

解决方案简单易行:我的显卡在兼容模式下运行。安装适当的propriatery驱动程序解决了这个问题。

因此,OpenGL-Engine崩溃了。 -.-'