Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create a function, that changes the UI
Forum Updated to NodeBB v4.3 + New Features

Create a function, that changes the UI

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomaschku
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      T 1 Reply Last reply
      1
      • VRoninV VRonin

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

        T Offline
        T Offline
        tomaschku
        wrote on last edited by
        #3

        @VRonin What was a member function again?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          http://www.cplusplus.com/doc/tutorial/classes/

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          T 1 Reply Last reply
          4
          • VRoninV VRonin

            http://www.cplusplus.com/doc/tutorial/classes/

            T Offline
            T Offline
            tomaschku
            wrote on last edited by
            #5

            @VRonin Oh, thank you!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved