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. Save Programm Settings internally + how to organize with folders?
Forum Updated to NodeBB v4.3 + New Features

Save Programm Settings internally + how to organize with folders?

Scheduled Pinned Locked Moved Solved General and Desktop
qt c++foldersettings
18 Posts 6 Posters 1.6k Views 5 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.
  • S sierdzio
    6 Mar 2024, 10:30

    @sierdzio said in Save Programm Settings internally + how to organize with folders?:

    Whats the best way to store settings for my programm internally? These settings should be read on every startup of the programm so it is essential to store them somehow within the programm. Maybe create a json inside the qrc and read and write there or is there a better way?

    Actually, now that I think about it again - if these are really static, built-in settings we are talking about you can simply create a c++ header file and store your stuff there. No need for QRC as such then.

    // settings.h
    Settings {
      constexpr int Setting1 = 1;
      constexpr QLatin1String SomeOtherSetting = "ABCD";
      // ...
    }
    

    But it's entirely up to you which solution you prefer more.

    S Offline
    S Offline
    StudentScripter
    wrote on 6 Mar 2024, 14:39 last edited by
    #4

    @sierdzio Thank you very much. How would i need to update the path? It looks like this right now:
    How can i for example put these files into a subfolder named "DockableItemsFolder"

    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(EditorWIPNeu
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
    		CustomDockableItemList.cpp 
                    CustomDockableItemList.h
    }
    
    S 1 Reply Last reply 6 Mar 2024, 15:37
    0
    • S StudentScripter
      6 Mar 2024, 14:39

      @sierdzio Thank you very much. How would i need to update the path? It looks like this right now:
      How can i for example put these files into a subfolder named "DockableItemsFolder"

      if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
          qt_add_executable(EditorWIPNeu
              MANUAL_FINALIZATION
              ${PROJECT_SOURCES}
      		CustomDockableItemList.cpp 
                      CustomDockableItemList.h
      }
      
      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 6 Mar 2024, 15:37 last edited by
      #5

      @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

      if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
          qt_add_executable(EditorWIPNeu
              MANUAL_FINALIZATION
              ${PROJECT_SOURCES}
      		DockableItemsFolder/CustomDockableItemList.cpp 
                      DockableItemsFolder/CustomDockableItemList.h
      }
      

      (Z(:^

      S 1 Reply Last reply 6 Mar 2024, 15:44
      0
      • S sierdzio
        6 Mar 2024, 15:37

        @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

        if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
            qt_add_executable(EditorWIPNeu
                MANUAL_FINALIZATION
                ${PROJECT_SOURCES}
        		DockableItemsFolder/CustomDockableItemList.cpp 
                        DockableItemsFolder/CustomDockableItemList.h
        }
        
        S Offline
        S Offline
        StudentScripter
        wrote on 6 Mar 2024, 15:44 last edited by
        #6

        @sierdzio Thank you very much and well, guess i have to use something different than headders cause the values should be modifiable and shall be saved as new standards when closing the application.

        open application --> set Standard values --> interact with application and change settings--> close Application and save new changed values as new standards

        Guess qrc is the way to go here or qsettings.

        S 1 Reply Last reply 6 Mar 2024, 20:32
        0
        • S StudentScripter
          6 Mar 2024, 15:44

          @sierdzio Thank you very much and well, guess i have to use something different than headders cause the values should be modifiable and shall be saved as new standards when closing the application.

          open application --> set Standard values --> interact with application and change settings--> close Application and save new changed values as new standards

          Guess qrc is the way to go here or qsettings.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Mar 2024, 20:32 last edited by
          #7

          @StudentScripter hi,

          QSettings is a good way to go. If you want to use JSON with it, you can leverage registerFormat.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • S Offline
            S Offline
            SimonSchroeder
            wrote on 7 Mar 2024, 07:46 last edited by
            #8

            Settings need to be changed in a separate file (or the registry on Windows). Qt does not provide a way to change the executable itself. Files inside qrc are read-only (even if they are separate files on disk, i.e. qrc files read at runtime).

            Every operating system has a default way of storing settings. Just use QSettings (with your "company" and application name) and it will store it in the right place. You can add default values for your settings with QSettings so that you can create the initial settings file.

            S 1 Reply Last reply 7 Mar 2024, 11:37
            0
            • S SimonSchroeder
              7 Mar 2024, 07:46

              Settings need to be changed in a separate file (or the registry on Windows). Qt does not provide a way to change the executable itself. Files inside qrc are read-only (even if they are separate files on disk, i.e. qrc files read at runtime).

              Every operating system has a default way of storing settings. Just use QSettings (with your "company" and application name) and it will store it in the right place. You can add default values for your settings with QSettings so that you can create the initial settings file.

              S Offline
              S Offline
              StudentScripter
              wrote on 7 Mar 2024, 11:37 last edited by
              #9

              @SimonSchroeder But doesn't create qsetting endless registry entrys while testing? How to get rid of them?

              S 1 Reply Last reply 7 Mar 2024, 11:55
              0
              • S StudentScripter
                7 Mar 2024, 11:37

                @SimonSchroeder But doesn't create qsetting endless registry entrys while testing? How to get rid of them?

                S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 7 Mar 2024, 11:55 last edited by
                #10

                @StudentScripter you can specify custom path where the settings will be saved (to a file, not registry). Then it is easy, when you need a "clean slate" you just delete the file.

                (Z(:^

                S 1 Reply Last reply 7 Mar 2024, 12:05
                0
                • S sierdzio
                  7 Mar 2024, 11:55

                  @StudentScripter you can specify custom path where the settings will be saved (to a file, not registry). Then it is easy, when you need a "clean slate" you just delete the file.

                  S Offline
                  S Offline
                  StudentScripter
                  wrote on 7 Mar 2024, 12:05 last edited by
                  #11

                  @sierdzio

                  Something like this? And than remove this path at the end when my development is finished to save it in the users registry?

                      QString filePath = "/path/to/your/settings.ini";
                      QSettings settings(filePath, QSettings::IniFormat);
                  
                  
                  J P S 3 Replies Last reply 7 Mar 2024, 12:22
                  0
                  • S StudentScripter
                    7 Mar 2024, 12:05

                    @sierdzio

                    Something like this? And than remove this path at the end when my development is finished to save it in the users registry?

                        QString filePath = "/path/to/your/settings.ini";
                        QSettings settings(filePath, QSettings::IniFormat);
                    
                    
                    J Offline
                    J Offline
                    JonB
                    wrote on 7 Mar 2024, 12:22 last edited by
                    #12

                    @StudentScripter Yes you can do that. Or you can just go into the Registry at "your "company" and application name " and delete that.

                    S 1 Reply Last reply 7 Mar 2024, 12:29
                    1
                    • S StudentScripter
                      7 Mar 2024, 12:05

                      @sierdzio

                      Something like this? And than remove this path at the end when my development is finished to save it in the users registry?

                          QString filePath = "/path/to/your/settings.ini";
                          QSettings settings(filePath, QSettings::IniFormat);
                      
                      
                      P Offline
                      P Offline
                      Pl45m4
                      wrote on 7 Mar 2024, 12:24 last edited by Pl45m4 3 Jul 2024, 12:29
                      #13

                      @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

                      And than remove this path at the end when my development is finished to save it in the users registry?

                      Like this, or you stick to the .ini file mode and just delete it in order to be re-created in a clean state by your program.

                      @JonB said in Save Programm Settings internally + how to organize with folders?:

                      Or you can just go into the Registry at "your "company" and application name " and delete that.

                      If only every software dev would do this... :)
                      That's why 99% of all Windows users have a bloated registry... because most programs don't delete all its entries even when you uninstall them.
                      Some leave it up to you while uninstalling to check/uncheck an option to keep or delete config. and "user data" in the registry, which is fine :)


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      0
                      • J JonB
                        7 Mar 2024, 12:22

                        @StudentScripter Yes you can do that. Or you can just go into the Registry at "your "company" and application name " and delete that.

                        S Offline
                        S Offline
                        StudentScripter
                        wrote on 7 Mar 2024, 12:29 last edited by
                        #14

                        @JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.

                        P J 2 Replies Last reply 7 Mar 2024, 12:34
                        0
                        • S StudentScripter
                          7 Mar 2024, 12:29

                          @JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.

                          P Offline
                          P Offline
                          Pl45m4
                          wrote on 7 Mar 2024, 12:34 last edited by
                          #15

                          @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

                          I don't want the endusers registry to get bloated over time.

                          You know what you write to registry. Every QSetting key is stored the way you set it up.
                          Unless you write (possibly) endless arrays to registry, the amount of keys should stay the same.
                          You have your "organisation" and your group, so you know where to find your keys.
                          How you delete them completely is mentioned here:

                          • https://forum.qt.io/topic/114416/deleting-all-registry-entries-under-an-organisation

                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          1
                          • S StudentScripter
                            7 Mar 2024, 12:29

                            @JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.

                            J Offline
                            J Offline
                            JonB
                            wrote on 7 Mar 2024, 12:49 last edited by JonB 3 Jul 2024, 12:50
                            #16

                            @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

                            @JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.

                            I don't understand the question. But what I can say is: when you go to production/have end users under Windows they will expect you store settings in the Registry rather than .ini files (which you won't much know where to put anyway). So it's all very well for you to decide that in your development environment you (seem to) want to use .ini file so you can delete it, but I don;t think you should do that in production/release and that means you will have different paths of code.

                            QSettings is only saving downward from one registry key (as mentioned earlier) so it's not too "polluting", and you are using the same company/application name the whole time so that's it. As for "bloated", the registry will likely be GB rather than MB big, so a few entries from you won't make much difference. Unless you are intending to save megabytes of information, which I doubt!

                            I don't know how you install your application to end users, but most Windows application installers delete application's registry key on uninstall.

                            S 1 Reply Last reply 7 Mar 2024, 13:25
                            3
                            • J JonB
                              7 Mar 2024, 12:49

                              @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

                              @JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.

                              I don't understand the question. But what I can say is: when you go to production/have end users under Windows they will expect you store settings in the Registry rather than .ini files (which you won't much know where to put anyway). So it's all very well for you to decide that in your development environment you (seem to) want to use .ini file so you can delete it, but I don;t think you should do that in production/release and that means you will have different paths of code.

                              QSettings is only saving downward from one registry key (as mentioned earlier) so it's not too "polluting", and you are using the same company/application name the whole time so that's it. As for "bloated", the registry will likely be GB rather than MB big, so a few entries from you won't make much difference. Unless you are intending to save megabytes of information, which I doubt!

                              I don't know how you install your application to end users, but most Windows application installers delete application's registry key on uninstall.

                              S Offline
                              S Offline
                              StudentScripter
                              wrote on 7 Mar 2024, 13:25 last edited by
                              #17

                              @JonB @Pl45m4 Well thanks that answered my questions. :) Have a nice day.

                              1 Reply Last reply
                              0
                              • S StudentScripter has marked this topic as solved on 7 Mar 2024, 13:26
                              • S StudentScripter
                                7 Mar 2024, 12:05

                                @sierdzio

                                Something like this? And than remove this path at the end when my development is finished to save it in the users registry?

                                    QString filePath = "/path/to/your/settings.ini";
                                    QSettings settings(filePath, QSettings::IniFormat);
                                
                                
                                S Offline
                                S Offline
                                SimonSchroeder
                                wrote on 8 Mar 2024, 07:26 last edited by
                                #18

                                @StudentScripter said in Save Programm Settings internally + how to organize with folders?:

                                QString filePath = "/path/to/your/settings.ini";

                                If you want to use an ini file, please use QStandardPath with ConfigLocation and don't invent your own place where to put the ini file.

                                1 Reply Last reply
                                2

                                13/18

                                7 Mar 2024, 12:24

                                • Login

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