Javascript设置的属性上的QML返回NaN

Javascript设置的属性上的QML返回NaN,javascript,qt,qml,Javascript,Qt,Qml,我正在使用java脚本在对象创建时设置QML对象的属性。 除了一个需要数字的参数外,它工作正常 这将调用脚本: Component.onCompleted: CreateVerticalGaugeScript.createVerticalGauge(300,10,300,300,"MAP",Dashboard,"MAP"); “地图”前的300是所需的数字。其他一切都在起作用 var component; var gauge; function createVerticalGauge(setW

我正在使用java脚本在对象创建时设置QML对象的属性。 除了一个需要数字的参数外,它工作正常

这将调用脚本:

Component.onCompleted: CreateVerticalGaugeScript.createVerticalGauge(300,10,300,300,"MAP",Dashboard,"MAP");
“地图”前的300是所需的数字。其他一切都在起作用

var component;
var gauge;
function createVerticalGauge(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
    component = Qt.createComponent("verticalbargauge.qml");
    console.log(setMaxValue)
    if (component.status == Component.Ready)
        finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty);
    else
        component.statusChanged.connect(finishCreation);
}

    function finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
        console.log(setMaxValue)
        if (component.status == Component.Ready) {
            gauge = component.createObject(adaptronicDash, {"id": setID, "gaugemaxvalue": setMaxValue,
                                               "gaugetext": Qt.binding(function(){return SetValueObject[SetValueProperty]}),
                                               "x": setX, "y": setY});
            gauge.width = setWidth;
            if (gauge == null) {
                // Error Handling
                //console.log("Error creating object");
            }
        } else if (component.status == Component.Error) {
            // Error Handling
            //console.log("Error loading component:", component.errorString());
        }
    }
现在,当创建对象时,它在QML中的值为NaN。在jas console.log中,我看到设置了值300

这是创建的QML:

import QtQuick 2.8
import QtQuick.Controls.Styles 1.4
import QtQuick.Extras 1.4
import QtQml.Models 2.2


Rectangle {
        id: initalID
        width: 100
        height: 80
        color: "transparent"
        antialiasing: false
        Drag.active: dragArea.drag.active

        property alias gaugetext: gaugetextfield.text
        property alias gaugemaxvalue: gauge.maximumValue

        MouseArea {
                  id: dragArea
                  width: parent.width
                  height: parent.height + 10 // easier to get
                  anchors.centerIn: parent
                  drag.target: parent
                  drag.axis: Drag.XAndYAxis
                  //onClicked: pieMenu.popup(mouseX, mouseY), console.log("clicked")
                }

        Gauge {
            id: gauge
            anchors.fill: parent
            anchors.margins: 10
            orientation : Qt.Horizontal
            minorTickmarkCount: 4
            tickmarkStepSize : 5000
            //labelStepSize: 50
            minimumValue: 0
            maximumValue: 10000

            //value: Dashboard.revs
            Behavior on value {
                NumberAnimation {
                    duration: 5
                }
            }
            Text {
                id: gaugetextfield
                font.pixelSize: (parent.height / 3)
                anchors.top : parent.top
                font.bold: true
                font.family: "Eurostile"
                color: "white"
                anchors.horizontalCenter: parent.horizontalCenter
            }
              style: GaugeStyle {
                valueBar: Rectangle {
                   implicitWidth:  rev.height /3
                    color: Qt.rgba(gauge.value / gauge.maximumValue, 0, 1 - gauge.value / gauge.maximumValue, 1)
                }
            }
      }
}

我使用属性别名gaugemaxvalue访问该值。如果我直接在Javascript中设置了一个数字,它就会工作。

您正在将Gauge
maximumValue
设置为300,
tickmarkStepSize
设置为5000

var component;
var gauge;
function createVerticalGauge(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
    component = Qt.createComponent("verticalbargauge.qml");
    console.log(setMaxValue)
    if (component.status == Component.Ready)
        finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty);
    else
        component.statusChanged.connect(finishCreation);
}

    function finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
        console.log(setMaxValue)
        if (component.status == Component.Ready) {
            gauge = component.createObject(adaptronicDash, {"id": setID, "gaugemaxvalue": setMaxValue,
                                               "gaugetext": Qt.binding(function(){return SetValueObject[SetValueProperty]}),
                                               "x": setX, "y": setY});
            gauge.width = setWidth;
            if (gauge == null) {
                // Error Handling
                //console.log("Error creating object");
            }
        } else if (component.status == Component.Error) {
            // Error Handling
            //console.log("Error loading component:", component.errorString());
        }
    }
通过将maximumValue更改为30000或注释掉tickmarkStepSize进行测试