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?

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.1k 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.
  • S Online
    S Online
    StudentScripter
    wrote on 6 Mar 2024, 09:56 last edited by
    #1

    So two smaller questions qt c++:

    1. 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?

    2. I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.

    Thanks a lot and have a nice day. :)

    S 1 Reply Last reply 6 Mar 2024, 10:02
    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.

      J Online
      J Online
      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
      • S StudentScripter
        6 Mar 2024, 09:56

        So two smaller questions qt c++:

        1. 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?

        2. I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.

        Thanks a lot and have a nice day. :)

        S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 6 Mar 2024, 10:02 last edited by
        #2

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

        So two smaller questions qt c++:

        1. 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?

        If you mean this to be read-only and not alterable by users then yes - using QRC is a great solution. Regarding format it is completely up to you - JSON is definitely nice and easy, CBOR gives more performance but is not readable to humans, or you can even use some super simple, custom INI parser.

        1. I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.

        You just put them in folders :-) And update paths in CMakeLists.txt file. That's it.

        If you want to make this a bit more modular, you can create (static) libraries out of your files and then link them to the executable.

        (Z(:^

        S 1 Reply Last reply 6 Mar 2024, 10:30
        1
        • S sierdzio
          6 Mar 2024, 10:02

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

          So two smaller questions qt c++:

          1. 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?

          If you mean this to be read-only and not alterable by users then yes - using QRC is a great solution. Regarding format it is completely up to you - JSON is definitely nice and easy, CBOR gives more performance but is not readable to humans, or you can even use some super simple, custom INI parser.

          1. I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.

          You just put them in folders :-) And update paths in CMakeLists.txt file. That's it.

          If you want to make this a bit more modular, you can create (static) libraries out of your files and then link them to the executable.

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 6 Mar 2024, 10:30 last edited by
          #3

          @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.

          (Z(:^

          S 1 Reply Last reply 6 Mar 2024, 14:39
          0
          • 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 Online
            S Online
            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 Online
                S Online
                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.

                SGaistS 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.

                  SGaistS Offline
                  SGaistS 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 Online
                      S Online
                      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 Online
                          S Online
                          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 Pl45m4P 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 Online
                            J Online
                            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);
                              
                              
                              Pl45m4P Offline
                              Pl45m4P 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 Online
                                S Online
                                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.

                                Pl45m4P 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.

                                  Pl45m4P Offline
                                  Pl45m4P 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 Online
                                    J Online
                                    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 Online
                                      S Online
                                      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

                                        1/18

                                        6 Mar 2024, 09:56

                                        • Login

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