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. QSettings remove

QSettings remove

Scheduled Pinned Locked Moved General and Desktop
12 Posts 6 Posters 7.8k 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 Offline
    S Offline
    stima_ua
    wrote on last edited by
    #1

    I need to remove some settings (OS Windows). My code above:

    @
    QString path = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\SharedDLLs";
    QString key = "C:\Windows\Microsoft.NET\Framework\v1.0.3705\microsoft.jscript.dll";
    QSettings settings(path, QSettings::NativeFormat);
    settings.remove(key);
    @

    But it does not work. I try:
    QString key = "C:/Windows/Microsoft.NET/Framework/v1.0.3705/microsoft.jscript.dll";
    or
    QString key = "C:\Windows\Microsoft.NET\Framework\v1.0.3705\microsoft.jscript.dll";
    But it does not work too. Can somebody help me?:)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      I you sure that there is such KEY? Looks my like a VALUE for me

      1 Reply Last reply
      0
      • BilbonSacquetB Offline
        BilbonSacquetB Offline
        BilbonSacquet
        wrote on last edited by
        #3

        Effectively it's a key, with values like 0x1 or 0x1000.

        Did you get the list of the keys with:
        @QStringList keys = settings.allKeys();@
        ?

        And did you have the right to change/remove this key?

        1 Reply Last reply
        0
        • BilbonSacquetB Offline
          BilbonSacquetB Offline
          BilbonSacquet
          wrote on last edited by
          #4

          I go on the sources and the philosophy of use of the settings, the current implementation doesn't allow the use of the '' in the key. The reason is simple, we have a conflict between 'the path' in the registry delimited too by a slash and the key itself. Qt tries to 'open' the path ...
          @
          QString rKey = escapedKey(uKey);

          // try to delete value bar in key foo
          LONG res;
          HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey));
          if (handle != 0) {
              res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
              RegCloseKey(handle);
          }
          

          @

          One solution is to remove the escaping or better to introduce a class QSettingsKey. But anyway for now it's impossible to remove or (even) change the value of a key having slash.

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yash
            wrote on last edited by
            #5

            Can you please show me complete solutions. I'm facing exactly same problem.

            http://kineticwing.com : Web IDE, QSS Editor
            http://speedovation.com : Development Lab

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              It may very well be that you don't have permission to write to the registry at that location. Windows is quite strict (and has become stricter with every version) on where an application can and can't write, both in the registry and on the file system. Even if the user has the necessary rights, that doesn't mean that the application does too.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                ScottR
                wrote on last edited by
                #7

                "The documentation":http://qt-project.org/doc/qt-5/qsettings.html#details specifically says you cannot do this, as BilbonSacquet has already said.

                "Do not use slashes ('/' and '') in section or key names; the backslash character is used to separate sub keys (see below). "

                "Note that the backslash character is, as mentioned, used by QSettings to separate subkeys. As a result, you cannot read or write windows registry entries that contain slashes or backslashes; you should use a native windows API if you need to do so."

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  Yash
                  wrote on last edited by
                  #8

                  This is my question on stack overflow
                  http://stackoverflow.com/questions/23315520/removing-key-which-contain-slash-using-win-api-registry-in-windows-or-using-qt

                  It's problem in windows standard locations in shared dll section.

                  I'm not able to remove it using any method. I've tried to use native also with no success. Above link contains my attempted code.

                  Also what Andre pointed out about permission level which I already done using manifest. I can clearly see windows admin icon on exe. So permission is not problem in my case.

                  Any help/suggestion is appreciated. Thanks.

                  http://kineticwing.com : Web IDE, QSS Editor
                  http://speedovation.com : Development Lab

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    ScottR
                    wrote on last edited by
                    #9

                    When using the native API, you do not need to replace '' with '/'.

                    1 Reply Last reply
                    0
                    • Y Offline
                      Y Offline
                      Yash
                      wrote on last edited by
                      #10

                      I tried with both type of slashes and I'm converting because Qt is treating it as path which is actually a key name like a trick if it can work but it can't.
                      Even I replaced with double "\" with "/"and with no change... with no luck in any of the cases.

                      http://kineticwing.com : Web IDE, QSS Editor
                      http://speedovation.com : Development Lab

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        Yash
                        wrote on last edited by
                        #11

                        I found solution not exactly but good workaround I think

                        My requirement was little more complicated I need to handle 32 bit/64 bit cases.
                        Here is solution

                        @
                        key = key.replace("/","\");

                        QString reg32 = qgetenv("windir")+"\\SysWOW64\\reg.exe";
                        QString reg64 = qgetenv("windir")+ "\\sysnative\\reg.exe";
                        
                        
                        QString command = tr("%1 DELETE \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs\" /v \"%2\" /f")
                                .arg(  is32Bit == true ? reg32 : reg64  )
                                .arg(key);
                        
                        QProcess *process = new QProcess(this);
                        process->start(command);
                        
                        
                        if (process->waitForStarted())
                        {
                            process->waitForFinished();
                            
                            QString l = process->readAllStandardOutput().simplified();
                            
                         
                        
                            Logger::Log_Info("RegistryCleaner", command);
                        
                            if(l.isEmpty())
                                Logger::Log_Error("RegistryCleaner", "Try again." );
                            else
                                Logger::Log_Info("RegistryCleaner", "Successfully done" );
                        }
                        else
                            qDebug() << process->readAllStandardError().simplified();
                        
                        delete process;
                        

                        @

                        For more info
                        http://stackoverflow.com/questions/23315520/removing-key-which-contain-slash-using-win-api-registry-in-windows-or-using-qt/23459080#23459080

                        http://kineticwing.com : Web IDE, QSS Editor
                        http://speedovation.com : Development Lab

                        1 Reply Last reply
                        0
                        • Y Offline
                          Y Offline
                          Yash
                          wrote on last edited by
                          #12

                          Please mark thread as solved if like solution ;)

                          http://kineticwing.com : Web IDE, QSS Editor
                          http://speedovation.com : Development Lab

                          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