Pregunta

I tried to

QMessageBox msgBox;
HKEY regKey;
WCHAR regKeyName;
DWORD lpcValueName = MAX_PATH;
LONG err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LPCWSTR("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE | KEY_READ | KEY_WOW64_64KEY, &regKey);
if (err == 0)
{
    msgBox.setText("success " + QString::number(err));
} else
{
    msgBox.setText("error " + QString::number(err));
};
msgBox.exec();

and application always show me the "error 2" msgbox. Why I can't open the registry key? I think LPCWSTR("HARDWARE\\DEVICEMAP\\SERIALCOMM") is not great idea.

¿Fue útil?

Solución

First of all you can use QSettings to read from and write to the registry. Secondly, the DEVICEMAP is probably read-only and protected. To check, open the registry editor (regedit) and see if you can change values there manually.

If your software is about reading and writing from serial ports, you can have a look at the QtSerialPort module.

Otros consejos

I would personally use QSettings for this task in a way something like this:

QSettings settings("HARDWARE\\DEVICEMAP\\SERIALCOMM", QSettings::NativeFormat);
qDebug() << settings.value("Default", "0").toString();

This is probably not the proper semantics, but you get the idea. You can read more upon the details in the official documentation.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top