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. Edit QSettings for an app outside the source
Forum Updated to NodeBB v4.3 + New Features

Edit QSettings for an app outside the source

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 6 Posters 601 Views 2 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.
  • E Offline
    E Offline
    Ewan Green
    wrote on last edited by Ewan Green
    #3

    No. The point is to do it from outside the app. In this scenario, the problem is that the developer didn't plan ahead, and the settings key is unusable or invalid causing bad behavior/crashes in the app. If I were the user, I shouldn't have to modify the source code to get it back to a usable state. With QSettings::IniFormat or something, I could just change the .ini file; it would be more straightforward as all the other QSettings formats have unified methods for changing the settings across platforms. The native format does not, so it's not quite as straightforward.

    Also, it doesn't have to be every single settings key; I just figured if there was an existing way to do it, that would be it.

    Ewan Green

    jsulmJ JonBJ 2 Replies Last reply
    0
    • E Ewan Green

      No. The point is to do it from outside the app. In this scenario, the problem is that the developer didn't plan ahead, and the settings key is unusable or invalid causing bad behavior/crashes in the app. If I were the user, I shouldn't have to modify the source code to get it back to a usable state. With QSettings::IniFormat or something, I could just change the .ini file; it would be more straightforward as all the other QSettings formats have unified methods for changing the settings across platforms. The native format does not, so it's not quite as straightforward.

      Also, it doesn't have to be every single settings key; I just figured if there was an existing way to do it, that would be it.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Ewan-Green said in Edit QSettings for an app outside the source:

      the settings key is unusable or invalid causing bad behavior/crashes in the app

      In that case the app should be fixed. An application should not crash just because there are unwanted/invalid settings.
      "If I were the user, I shouldn't have to modify the source code to get it back to a usable state" - there is no need to modify source code, user can modify the settings. For settings in registry there is regedit.exe, ini files can be edited in any text editor.
      You can also implement a function in your app which resets the settings to their default values.

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #5

        @Ewan-Green said in Edit QSettings for an app outside the source:

        The native format does not, so it's not quite as straightforward.

        The native format varies from platform to platform. It is the Windows registry on that platform, INI format text files on Linux, and CFPreferences API in the Apple world. There is, therefore, no single method.

        Assuming such a reset option is infrequently required you could use a command line switch to trigger a clear before any GUI is started (and potentially uses an invalid value blindly). Something like

        int main(int argc, char **argv) {
          QApplication app(argc, argv);
          QCoreApplication::setOrganizationName("MySoft");
          QCoreApplication::setOrganizationDomain("mysoft.com");
          QCoreApplication::setApplicationName("Unicorn Fun");
          QCoreApplication::setApplicationVersion("1.0");
          
          QCommandLineParser parser;
          parser.setApplicationDescription("Unicorn herding application");
        
          QCommandLineOption resetOption("r", 
            QCoreApplication::translate("main", "Reset default settings") );
          parser.addOption(resetOption);
          ...
          parser.process(app);
        
          bool reset = parser.isSet(resetOption);
          if (reset) {
            QSettings settings;
            settings.clear();
            // or whatever passes for "reset" options
          }
          
          // start GUI etc.
          return app.exec();
        }
        
        1 Reply Last reply
        4
        • E Ewan Green

          No. The point is to do it from outside the app. In this scenario, the problem is that the developer didn't plan ahead, and the settings key is unusable or invalid causing bad behavior/crashes in the app. If I were the user, I shouldn't have to modify the source code to get it back to a usable state. With QSettings::IniFormat or something, I could just change the .ini file; it would be more straightforward as all the other QSettings formats have unified methods for changing the settings across platforms. The native format does not, so it's not quite as straightforward.

          Also, it doesn't have to be every single settings key; I just figured if there was an existing way to do it, that would be it.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #6

          @Ewan-Green
          I still don't know what you are asking for.

          If you want to alter the settings content, for whatever reason, from within the Qt app we have shown for example QSettings methods to clear all the keys, or remove individual ones, or you can do whatever you want.

          The point is to do it from outside the app.
          If I were the user, I shouldn't have to modify the source code to get it back to a usable state.

          If this is what you want, of course the user does not have to modify your source code. If, say, your platform is Windows then the native format naturally saves to the Registry, and you must know that Windows supplies the Registry Editor (regedit) to allow users --- with suitable permissions --- to browse and edit entries from a UI to their heart's content, including those saved by a Qt application. There are thousands of articles on the web telling people to do this for all sorts of purposes. Which seems to be exactly what you are complaining does not exist?

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Ewan Green
            wrote on last edited by Ewan Green
            #7

            I was asking if there was a tool of the same nature available cross-platform for these kind of things, because of the fact that the native format varies from platform to platform. This thread is getting needlessly backhanded.

            74aeb135-21ca-4a68-ab10-29287a754b8d-image.png

            This is not a theoretical situation. In this app, the last saved MIDI port number is no longer available, so it crashes when trying to open said port. I'd love to go back in time and make the developer aware of this issue, but it hasn't been maintained for quite some time.

            Ewan Green

            JonBJ W 2 Replies Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on last edited by
              #8

              You could probably create a simple utility where all it basically does is create a QSettings instance with the same organization and application names as your application and then call QSettings::clear() as has already been mentioned. I'm not if you have to worry about the fallback settings locations. Since those are generally not writeable when run as a user, those settings should not have gotten corrupted.

              jsulmJ 1 Reply Last reply
              1
              • M mchinand

                You could probably create a simple utility where all it basically does is create a QSettings instance with the same organization and application names as your application and then call QSettings::clear() as has already been mentioned. I'm not if you have to worry about the fallback settings locations. Since those are generally not writeable when run as a user, those settings should not have gotten corrupted.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @mchinand As I wrote before an app should handle its settings in a way it does not crash just because some settings are invalid...
                So, instead of implementing work-arounds (like some tools to fix settings) fix your app and make sure it is robust.
                If a developer would tell me I have to use a tool to fix the settings to prevent his/her app from crashing I would look for alternatives to that app...

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

                M 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @mchinand As I wrote before an app should handle its settings in a way it does not crash just because some settings are invalid...
                  So, instead of implementing work-arounds (like some tools to fix settings) fix your app and make sure it is robust.
                  If a developer would tell me I have to use a tool to fix the settings to prevent his/her app from crashing I would look for alternatives to that app...

                  M Offline
                  M Offline
                  mchinand
                  wrote on last edited by mchinand
                  #10

                  @jsulm Yes, you are correct, if an additional utility has to be installed to fix a corrupted settings, might as well just install an updated version of the application that can gracefully handle a bad settings value.

                  1 Reply Last reply
                  0
                  • E Ewan Green

                    I was asking if there was a tool of the same nature available cross-platform for these kind of things, because of the fact that the native format varies from platform to platform. This thread is getting needlessly backhanded.

                    74aeb135-21ca-4a68-ab10-29287a754b8d-image.png

                    This is not a theoretical situation. In this app, the last saved MIDI port number is no longer available, so it crashes when trying to open said port. I'd love to go back in time and make the developer aware of this issue, but it hasn't been maintained for quite some time.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #11

                    @Ewan-Green
                    As said before, you have two choices, depending on what you want.

                    If you want one tool which works cross-platform and on native saved settings, you have only one choice: Qt itself. Since only that has support for cross-platform and native. Just like the code is now.

                    You then have a choice with Qt:

                    • Write a standalone utility, which allows whatever entries to be viewed/edited enough to deal with your cases. use that to "clear up" your current entries.
                    • Put error handling into your existing application, so that if, say, it throws an error like you show the code traps that and takes whatever appropriate remedial action, e.g. updating a value or deleting it or whatever.

                    Either of these might use the kind of QSettings we have been referring to, such as clear() or removeKey(). Which do work cross-platform/native.

                    Only the first of these satisfies your statement "The point is to do it from outside the app.".

                    The other way of doing that is to use an existing, non-Qt, external tool for the target platform. Such as regedit for the Windows Registry.

                    I don't know what else you could be asking for.

                    1 Reply Last reply
                    0
                    • E Ewan Green

                      I was asking if there was a tool of the same nature available cross-platform for these kind of things, because of the fact that the native format varies from platform to platform. This thread is getting needlessly backhanded.

                      74aeb135-21ca-4a68-ab10-29287a754b8d-image.png

                      This is not a theoretical situation. In this app, the last saved MIDI port number is no longer available, so it crashes when trying to open said port. I'd love to go back in time and make the developer aware of this issue, but it hasn't been maintained for quite some time.

                      W Offline
                      W Offline
                      wrosecrans
                      wrote on last edited by
                      #12

                      @Ewan-Green said in Edit QSettings for an app outside the source:

                      I was asking if there was a tool of the same nature available cross-platform for these kind of things, because of the fact that the native format varies from platform to platform.

                      On Windows, use regedit. On Linux, edit the relevant text file. On MacOS, use the Mac settings command line tool, etc. The reason that Qt uses the native config system on each platform is so that if a user does need to tinker and hack with the settings, they don't need anything Qt specific and can do it the "normal" way the user is already familiar with on that platform.

                      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