How to add/change registry in qt?

6.2k views Asked by At

I tried

QSettings mSettings; 
mSettings.setValue("HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/USBTOR/Start",   4);

This didn't work.

2

There are 2 answers

0
Mohammad Amir On BEST ANSWER
  1. Initialize QSettings with registry path (Make sure to use backslash for registry path)

    QSettings settings("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBTOR", QSettings::NativeFormat);

  2. Set Value

    settings.setValue("Start", 4);

0
TheDarkKnight On

As Qt is a multi-platform SDK, it is designed to hide implementation details such as where in the registry on Windows a settings is being stored. As it states:

The QSettings class provides persistent platform-independent application settings....QSettings is an abstraction around these technologies

If you look at the documentation for QSettings there is no available constructor or function to set a specific registry key; only Windows supports the registry and other platforms use different mechanisms.

If you're trying to save settings for an application, don't worry about where or how they are stored. However, if you want to change values directly in the registry, I suggest using functions from the Windows SDK, not QSettings.