简体   繁体   中英

Signal in QML that is triggered when one of two spinBox values are changed

I have two spinBoxes ( spinBox1 and spinBox2 ) and I need one signal that sends the values of both of the spinboxes and I need it to be triggered when either one of the values of the spinboxes is changed. How can I do this?

I will connect this with C++ slots and do math with it in C++ later. I have sucessfully been able to do all those things with single argument signals that have a single trigger but this is a little more complicated.

Help is much needed and appreciated.

  1. Create a signal that contains 2 parameters.
  2. Create an internal function that is called when either of the SpinBoxes change value.
  3. Inside that internal function from #2, emit the signal from #1.

Connect your signal to a slot that takes 2 parameters.

Rectangle {
    signal somethingChanged(double, double)

    function exportSignals() {
        somethingChanged(spinBox1.value, spinBox2.value)
    }

    SpinBox {
        id: spinBox1
        onValueChanged: exportSignals()
    }
    SpinBox {
        id: spinBox2
        onValueChanged: exportSignals()
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM