QSettings remove

  • 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);

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

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

  • 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?

  • 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()));


    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.

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

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

  • "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."

  • This is my question on stack overflow

    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.

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

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

  • 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  )
    QProcess *process = new QProcess(this);
    if (process->waitForStarted())
        QString l = process->readAllStandardOutput().simplified();
        Logger::Log_Info("RegistryCleaner", command);
            Logger::Log_Error("RegistryCleaner", "Try again." );
            Logger::Log_Info("RegistryCleaner", "Successfully done" );
        qDebug() << process->readAllStandardError().simplified();
    delete process;


    For more info

  • Please mark thread as solved if like solution ;)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.