相关疑难解决方法(0)

如何使用QML模型?

我有一个用qml和c ++编写的GUI.有2个组合框(qt control 5.1).只要第一个组合的值发生变化,第二个组合框就必须在运行时更新.

maincontext->setContextProperty("typemodel", QVariant::fromValue(m_typemodel));

maincontext->setContextProperty("unitmodel", QVariant::fromValue(m_unitmodel));
Run Code Online (Sandbox Code Playgroud)

这是我从c ++给qml的两个模型.

ComboBox {
    id: typebox

    anchors.left: text1.right
    anchors.leftMargin: 5
    signal changed(string newtext)

    width: 70
    height: 23
    anchors.top: parent.top
    anchors.topMargin: 37
    model: typemodel

    onCurrentTextChanged: {

        mainwin.unitGenerator(typebox.currentText);

    }
Run Code Online (Sandbox Code Playgroud)

这是第一个组合框.如您所见,每次更改第一个组合框的值时,第二个组合框的c ++模型都会更新(mainwin.unitGenerator(typebox.currentText)).但它似乎没有更新组合框的模型.

如何在运行时更新qml的模型?

c++ qt combobox qml

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

combobox ×1

qml ×1

qt ×1