QML:如何实现 child 的信号处理程序

QML: How to implement signal handler of a child

我正在 Qt Creator 中编辑组件。它建议我将组件拆分为 UI 而不是 UI 部分。我的组件公开了 2 个自定义属性。

ComponentViewForm {
    property string step: '0'
    property string setStep: '0'
}
  1. UI-Part 中的 TextInput 绑定到 step
  2. 它应该在 onAccepted 处理程序中设置 属性 setStep

第一个很简单。绑定可以直接在UI-Editor中编辑 但是如何实现 child 的 signal-handler 呢? 我已经在 UI 中直接实现了它。

TextInput {
    id: step
    text: parent.step
    onAccepted:
    {
        parent.setStep = text
    }
}

可以,但是 Qt-Creator 拒绝在 UI-mode 中打开它。

您可以 export 来自您的 ComponentViewFormTextInput。在 Qt Quick UI 表单编辑器的 Navigator 选项卡中有一个 Export 小按钮。假设TextInput的id是stepInput,ComponentViewForm.ui.qml在点击Export[后源码中应该有别名属性property alias stepInput: stepInput =25=] 按钮。

您可以在 ComponentView.qml 中实现 属性 绑定和信号处理程序,如下所示:

ComponentViewForm {
    property string step: '0'
    property string setStep: '0'

    stepInput.text: step
    stepInput.onAccepted:
    {
        setStep = stepInput.text;
    }
}