Important: Please read the Qt Code of Conduct -

Is there any way of knowing the current value repeatedly when a valuechanged() signal is emitted by slider?

  • while i am implementing
    @QObject::connect(mb, SIGNAL(valuechanged(int)),.............);@
    In this case how can i know what is the value at each time.I want this because at particular value i want to call a function.

  • Create a slot that takes an integer value. In that slot, check if the received number matches the number you're looking for, call the function you want to call. Connect the valueChanged signal to your slot.

    Keep in mind that you might not receive the number you are looking for. valueChanged() doesn't get called at every number.

  • Ok thank's i was also trying in the same way but Is there any other way to do this ?

  • What do you want to achieve? That is, why do you want to call that function when the slider hits a specific number?

  • actually near the slider i have a speaker image. I want to change speaker image according to slider handle position. Speaker image can be changed by calling set_image(int image_index) slot. So for that at particular position of slider handle position i have to call set_image slot.
    The problem here is that the set_image slot is already written and i can't edit it.

  • Right. It is wise to check the ranges, rather than the bordering values.

    Let's assume the set_image() function doesn't update unless it has to, else get the current index and compare. Assume range is 0-100 and there are four images.

    void Thingy::updateIconForValueBluntly(int v)

    void Thingy::updateIconForValueSmartly(int v)
    if (v < 10)
    else if (v < 30)
    else if (v < 65)

    void Thingy::updateIconForValueSomewhatPythonically(int v)
    static const QVector vec = QVector() << 10 << 30 << 65 << 100;

    for (int i = 0; i < vec.size(); ++i) {
        if (v < {
    set_image(vec.count() - 1);


    Probably goes without saying, all code is untested.

  • ok thank you

Log in to reply