PDA

View Full Version : How can I read \Device\serial0 value with QSettings in windows registry ?



Tronshort
19th September 2008, 15:22
Hi, I want to read in the windows registry the value of the key "\Device\Serial0" located in:
HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOM M

The problem is QSetting seems to convert all my "\" to "/".

So when I do:

QSettings settings("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOM M", QSettings::NativeFormat);

then

QString result = settings.value("\\Device\\Serial0").toString();

it actually looks for a value located in:
HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOM M\\Device\\Serial0

Of course there is no value in this location since "\\Device\\Serial0" is not a path but the name of the key.

Typically, the value of the key called "\\Device\\Serial0" is COM1

How can I read this value ?

Thank you

Tronshort
19th September 2008, 16:43
I reply to myself:

Qsettings documentation says it is not possible to read or write keys with backslashes:

http://doc.trolltech.com/4.3/qsettings.html

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