문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top