Valentin H
Valentin H

Reputation: 7448

QML: How to implement signal handler of a child

I'm editing a component in Qt Creator. It suggested me to split the component in UI and not UI parts. My components exposes 2 custom properties.

ComponentViewForm {
    property string step: '0'
    property string setStep: '0'
}
  1. A TextInput inside the UI-Part is bound to step
  2. It should set the property setStep in onAccepted handler.

First one is easy. The binding can be edited in UI-Editor directly But how do I implement the signal-handler of the child? I've implemented it directly in the UI.

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

It works, but Qt-Creator rejects to open it in UI-mode any more.

Upvotes: 2

Views: 1423

Answers (1)

mcchu
mcchu

Reputation: 3359

You can export the TextInput from your ComponentViewForm. There's a small Export button in the Navigator tab in Qt Quick UI forms editor. Assume that the id of TextInput is stepInput, ComponentViewForm.ui.qml should have an alias property property alias stepInput: stepInput in source code after you click the Export button. Export

You can implement property binding and signal handlers in ComponentView.qml like this:

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

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

Upvotes: 2

Related Questions