Important: Please read the Qt Code of Conduct -

Inbuilt QSlider functions value() and valueChanged(int) do not return the same result

  • Hey guys,

    I'm pretty new to Qt, so I hope my questions won't be that stupid.
    I'm trying to write a small program, which should be able to convert one colorspace into another. I was trying to realize that with sliders.What I have are three sliders for RGB and maybe for example three sliders for CMY.

    I want to be able to move one slider (for example R), get the values of the other two (for example GB) -> convert them -> set the Slider values of CMY.

    What I realized was that the inbuilt QSlider functions value() and valueChanged(int) do not return the same result.

    In code, this means
    SIGNAL and SLOT Stuff
    @connect(ui->rSlide, SIGNAL(sliderMoved(int)), this, SLOT(getSliderValues()));
    connect(ui->gSlide, SIGNAL(sliderMoved(int)), this, SLOT(getSliderValues()));
    connect(ui->bSlide, SIGNAL(sliderMoved(int)), this, SLOT(getSliderValues()));@

    @int MainWindow::getSliderValues()
    red = ui->rSlide->value();
    green = ui->gSlide->value();
    blue = ui->bSlide->value()

    Does not return the same Slider result then
    @connect(ui->rSlide, SIGNAL(sliderMoved(int)), this, SLOT(convertFromRGB(int)));
    connect(ui->gSlide, SIGNAL(sliderMoved(int)), this, SLOT(convertFromRGB(int)));
    connect(ui->bSlide, SIGNAL(sliderMoved(int)), this, SLOT(convertFromRGB(int)));@

    @void MainWindow::convertFromRGB(int test)
    cout << test << endl;

    Both Versions return a different result, they differ by 2.
    Did you guys ever stumble upon something like that? Or could you tell me if I'm doing something wrong? Because I would really like to implement the first version.

    Thanks for all your time and in advance for the answers.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Pretty strange indeed, can you check whether the slider has mouse tracking enabled ? If not, the difference is normal, otherwise there's something wrong.

    In any case, the valueChanged signal seems more suited to your purpose.

    Also, what combo of Qt/OS/Compiler are you using ?

Log in to reply