Create a function, that changes the UI



  • Hello,

    My first Question here is:
    I've got a Project where you must choose an option from three RadioButtons and one checkbox.
    Because every RadioButton has it own Text and Input fields to disable/enable, when it's clicked and every button must check every times, if the Checkbox is checked.
    In result, the Code was too long, so I had the idea to make a function with arguments.

    I've tried to write the function in MainWindow.cpp, but it resulted in a error: "'ui' was not declared in this scope"

    The function:

    void limit(const QString& who)
    {
        switch (who) {
        case "a":
            if(ui->checkobx_1->checked()) {
            //Actived
            ui->text_a_scope->setEnabled(true);
            ui->input_a_scope->setEnabled(true);
            ui->text_b_scope->setEnabled(true);
            ui->input_b_scope->setEnabled(true);
    
            //Deactived
            ui->input_c_scope->setEnabled(false);
            ui->input_d_scope->setEnabled(false);
            ui->text_c_scope->setEnabled(false);
            ui->text_d_scope->setEnabled(false);
            }
            break;
    
        case "b":
            //Same Code as above, but only a little bit changed
            break;
    
        case "c":
            //Same Code as above, but only a little bit changed
            break;
        }
    }
    

    Simply writing it into main.cpp also don't helped.



  • you need to declare limit as a member function (aka method) of MainWindow



  • @VRonin What was a member function again?





  • @VRonin Oh, thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.