QSettings windows registry reading fails on certain keys
Hi all
I'd like to read the value of a certain key in the registry. Code is easy enough:
Code:
QSettings settings
("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM",
QSettings::NativeFormat);
QString sComPort
= settings.
value(keyList
[0],
"").
toString();
Note that I started with a key string, but as I saw there was something wrong I've tested it with reading the available keys and using that buffer to make sure the key is correct. The problem is that the value is always empty, even though there is a key with a value.
Going deeper into this, the key name is e.g. "/Device/Serial0". And this is where the problem starts. Digging into the QSettings code, value() will call actualKey() which calls normalizedKey(). normalizedKey() returns a string that never starts nor ends with a slash. So it is actually using "Device/Serial0" which doesn't exist!
Can we somehow ask the value without adjusting the key? It seems weird that the Qt lib changes our requested key behind our backs...
Re: QSettings windows registry reading fails on certain keys
Does anyone have an idea on how to solve this?
Re: QSettings windows registry reading fails on certain keys
Reading the registry in this case - is a bad idea.
Look ready implementation, e.g. for QtSerialPort (class SerialPortInfo) or another libraries.
To enumerate devices need to use Windows SetupAPI.
Re: QSettings windows registry reading fails on certain keys
Thanks for the idea. I've tried this with SerialPortInfo::availablePorts(), but the port I need doesn't really "exist" as a serial port (it is some kind of virtual comm device). So unfortunately this won't work for me.
Re: QSettings windows registry reading fails on certain keys
Your virtual device is present into Device Manager?
Re: QSettings windows registry reading fails on certain keys
No it isn't listed there.
Edit: to be fair, I'm not sure why that would be relevant. What if I wanted to read a completely different key starting with a "/"?
Re: QSettings windows registry reading fails on certain keys
Quote:
No it isn't listed there.
Then yes, you need to read the registry. Instead QSettings, try WinAPI I think it will be easier.