Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Save QRadioButton Selection

Save QRadioButton Selection

Scheduled Pinned Locked Moved Solved Qt for Python
9 Posts 6 Posters 1.0k Views
  • 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.
  • N Offline
    N Offline
    Neeraj2020
    wrote on last edited by
    #1

    Hi All,

    I am building an application that has a function list connected devices i.e. COM Ports. Now, I have a list of some QRadioButton and they are selected by the user and then I would like to save the user selection state for the next run time.

    Could you help me with this issue, as I am not getting the part how can I save users selection for an application?

    The nearest functioning example can also be seen in Mouse properties in control panel as user selects the state and apply it. When next time user open the setting it is the last changed state, which user made.

    Regards,
    Neeraj Singhal

    jsulmJ 1 Reply Last reply
    0
    • N Neeraj2020

      Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?

      I have a list or ports
      o COM1
      o COM2
      o COM3

      by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #8

      @Neeraj2020
      And to complete @jsulm's answer, to read back & restore the setting, something like (I assume you have your buttons in a QButtonGroup()):

      QSettings settings("MySoft", "My App");
      QString val = settings.value("ComPorts/selected", "").toString());
      if (!val.isEmpty())
      {
          QList<QRadioButton *> buttons = theRadioButtonGroup()->buttons();
          for (QRadioButton * button : buttons)
              if (button->text() == val)
                  button->setChecked(true);
      }
      
      1 Reply Last reply
      4
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        Use QSettings to save the selection when user changes it (or when application is closing), and then to load it when application starts up.

        (Z(:^

        N 1 Reply Last reply
        5
        • N Neeraj2020

          Hi All,

          I am building an application that has a function list connected devices i.e. COM Ports. Now, I have a list of some QRadioButton and they are selected by the user and then I would like to save the user selection state for the next run time.

          Could you help me with this issue, as I am not getting the part how can I save users selection for an application?

          The nearest functioning example can also be seen in Mouse properties in control panel as user selects the state and apply it. When next time user open the setting it is the last changed state, which user made.

          Regards,
          Neeraj Singhal

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @Neeraj2020 Take a look at https://doc.qt.io/qt-5/qsettings.html
          You can store settings in a file and on Windows alternatively in Registry.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          5
          • sierdzioS sierdzio

            Use QSettings to save the selection when user changes it (or when application is closing), and then to load it when application starts up.

            N Offline
            N Offline
            Neeraj2020
            wrote on last edited by Neeraj2020
            #4
            This post is deleted!
            1 Reply Last reply
            0
            • N Offline
              N Offline
              Neeraj2020
              wrote on last edited by
              #5

              Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?

              I have a list or ports
              o COM1
              o COM2
              o COM3

              by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.

              Pablo J. RoginaP jsulmJ JonBJ 3 Replies Last reply
              0
              • N Neeraj2020

                Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?

                I have a list or ports
                o COM1
                o COM2
                o COM3

                by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.

                Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #6

                @Neeraj2020

                I read about QSettings but still dont know how to save the the button selection for the user

                Have you tried any example for QSettings?

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • N Neeraj2020

                  Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?

                  I have a list or ports
                  o COM1
                  o COM2
                  o COM3

                  by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @Neeraj2020 said in Save QRadioButton Selection:

                  I read about QSettings but still dont know how to save the the button selection for the user?

                  Did you try anything already?
                  There are even examples.
                  Could be like this:

                  QSettings settings("MySoft", "My App");
                  settings.setValue("ComPorts/selected", selectedRadioButton->text());
                  

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  5
                  • N Neeraj2020

                    Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?

                    I have a list or ports
                    o COM1
                    o COM2
                    o COM3

                    by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @Neeraj2020
                    And to complete @jsulm's answer, to read back & restore the setting, something like (I assume you have your buttons in a QButtonGroup()):

                    QSettings settings("MySoft", "My App");
                    QString val = settings.value("ComPorts/selected", "").toString());
                    if (!val.isEmpty())
                    {
                        QList<QRadioButton *> buttons = theRadioButtonGroup()->buttons();
                        for (QRadioButton * button : buttons)
                            if (button->text() == val)
                                button->setChecked(true);
                    }
                    
                    1 Reply Last reply
                    4
                    • N Offline
                      N Offline
                      Neeraj2020
                      wrote on last edited by
                      #9

                      Thanks to all @sierdzio @jsulm @Pablo-J-Rogina @Denni-0 @JonB

                      1 Reply Last reply
                      1

                      • Login

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