PDA

View Full Version : QSettings and Windows registry - removing a key



lxman
29th July 2011, 16:43
I have an application which I am using an installer to create an installer package for Windows. As part of the install process, the installer puts a data file into the {localappdata} directory, which varies according to the different flavor of os. In order for my app to know positively where the installer placed this file, the installer writes a key to the registry with the path. Then, when my app starts up, it looks for the key, and if present, sets that value so that it can find the data file.
After the first run, the application stores this path in its own QSettings object. Therefore, after reading this key, I would like to delete it. That is where I am having a spot of difficulty.
The key is HKCU/Temp_fsfdb/data_path/"path string"

I have tried
QSettings settings("HKEY_CURRENT_USER", QSettings::NativeFormat);
settings.remove("Temp_fsfdb");
and
QSettings settings("HKEY_CURRENT_USER/Temp_fsfdb", QSettings::NativeFormat);
settings.remove("Temp_fsfdb");
neither of which have garnered success.

I have also tried
QSettings settings("HKEY_CURRENT_USER/Temp_fsfdb", QSettings::NativeFormst);
settings.beginGroup("Temp_fsfdb");
settings.remove("");
settings.endGroup();
Again, no joy.

Would someone be willing to show me the proper way to use remove() or perhaps clear() to accomplish removal of the Temp_fsfdb and it's descendants?

lxman
29th July 2011, 21:43
For the record, I found what "works." I don't entirely know if this is correct, but it does the job on wine as well as on an XP virtual box that I'm running.


QSettings settings("HKEY_CURRENT_USER\\Temp_fsfdb", QSettings::NativeFormat);
QString path = settings.value("data_path").toString();
settings.remove("");