Reputation: 211
I'd like my Qt application to access the windows registry. I did some research that QSettings is probably the way to go. Let's say I want to put my key/value under here: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\testApp" and my key is "start" and value is "4".
1.How do I create my key/value? I have tried
QSettings settings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\testApp", QSettings::NativeFormat);
settings.setValue("Start", 4);
but nothing happen. I think it maybe because "testApp" is not there before? How can I create the "testApp" class?
2.how can I delete what I created using QSettings? Need to delete the key/value as well as the "testApp" class.
Thanks!
Upvotes: 0
Views: 1516
Reputation: 108
I have done creation successfully. Creation is like modification, if path does not exists, it will be created. At least at allowed scope. Trying to set keys in Microsoft/windows domain could be part of your issue.
First you set, the organization and application name. Then each QSettings created with default constructor will take those informations, and when you try to set a specific value, it will create the structure in the registry:
QCoreApplication::setOrganizationName("MyCompany");
QCoreApplication::setApplicationName("testApp");
...
QSettings Settings;
Settings.setValue("start", 4);
will create registry key start with value 4 under
HKEY_CURRENT_USER\Software\MyCompany\testApp\
Afterwards, every call to QSettings::setValue will modify the value of given key.
I don't know about deletion.
Upvotes: 1
Reputation: 50
You can't.
QSettings may use the Windows registry as a backend, on the Windows platform, to store its settings.
It is not a general purpose API to access the registry.
Upvotes: 0