Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt Quick:如何从组合框中获取当前文本_Qt_Qml_Qtquick2_Qtquickcontrols2 - Fatal编程技术网

Qt Quick:如何从组合框中获取当前文本

Qt Quick:如何从组合框中获取当前文本,qt,qml,qtquick2,qtquickcontrols2,Qt,Qml,Qtquick2,Qtquickcontrols2,我尝试从ComboBox的当前索引中获取文本model.get(scale).text方法不起作用,它只获取第一个索引 import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import QtQuick.Controls.Material 2.0 ApplicationWindow { visible: true width: 200 height: 200 title:

我尝试从ComboBox的当前索引中获取文本
model.get(scale).text方法不起作用,它只获取第一个索引

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.0
ApplicationWindow {
    visible: true
    width: 200
    height: 200
    title: qsTr("Hello World")
Column{
    anchors.horizontalCenter: parent.horizontalCenter
    id:optionsColumn
    spacing: 5
    anchors.fill : parent
    anchors.topMargin    : 15
    anchors.bottomMargin : 15
    anchors.leftMargin :15
    anchors.rightMargin  : 15
    ComboBox {
        id: scale
        anchors.horizontalCenter: parent.horizontalCenter
        editable: true
        inputMethodHints: Qt.ImhDigitsOnly
        currentIndex: 1
        model: ListModel {
            id: model
            ListElement { text: "500" }
            ListElement { text: "1000" }
            ListElement { text: "2000" }
            ListElement { text: "5000" }
            ListElement { text: "10000" }
            ListElement { text: "25000" }
        }
        onAccepted: {
            id:maccepted
            if (find(editText) === -1)
                model.append({text: editText})
        }
    }
    Button{
        id:showtext
        text: "Scale to text"
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: {
            var a=parseFloat(model.get(scale).text)
            scaletext.text=a
        }
    }
    TextField{
        id:scaletext
        anchors.horizontalCenter: parent.horizontalCenter
        readOnly: true
    }
}
}
玩得开心

onClicked: {
  //var a=parseFloat(model.get(scale).text)
  scaletext.text = scale.currentText; 
}

你应该树立正确的榜样
ComboBox.accepted
已在
QtQuick.Controls 2.2
中引入,在导入的
2.0
中不可用。您对
model.get(scale).text的具体期望是什么
model.get()。我从Qt文档中引用了它。现在scale.currentText按预期工作。您似乎有奇怪的文档。我找不到接受
QtObjects
get
-方法。我只能从ComboBox文档中找到一个。我引用了'onCurrentIndexChanged:console.debug(cbItems.get(currentIndex.text+),“+cbItems.get(currentIndex.color)'