Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Value from the "ScrollBar" for "switch"



  • Hi!
    How to get value from the scroll bar for switch?

    oid MainWindow::on_pushButton_clicked()
    {
        
        ui->horizontalScrollBar->setRange(0, 8);
        
        switch(ui->horizontalScrollBar->value()){
        case ui->horizontalScrollBar->value(1): {
        
        }
        case ui->horizontalScrollBar->value(2): {
            
        }
    }
    

  • Moderators

    Hi. case labels take constant expressions, so simply:

    switch(ui->horizontalScrollBar->value()) {
        case 1: {
        }
        case 2: {
        }        
    }
    

    Don't forget to put break; between those cases so you don't accidentaly fall through.


  • Moderators

    Hi. case labels take constant expressions, so simply:

    switch(ui->horizontalScrollBar->value()) {
        case 1: {
        }
        case 2: {
        }        
    }
    

    Don't forget to put break; between those cases so you don't accidentaly fall through.


Log in to reply