Vinay Kulkarni
Vinay Kulkarni

Reputation: 85

How to add/change registry in qt?

I tried

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

This didn't work.

Upvotes: 3

Views: 6487

Answers (2)

TheDarkKnight
TheDarkKnight

Reputation: 27611

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 stated in the QSettings class documentation:

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

If you look at the documentation for QSettings member functions 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.

Upvotes: 3

Mohammad Amir
Mohammad Amir

Reputation: 353

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

Upvotes: 10

Related Questions