Qt - write to registry 32/64 issue

南楼画角 提交于 2019-12-12 06:36:29

问题


I'm writing a Qt application for windows, and using windows 7 64 bit.

The application has to write to the registry, I tried to use QSettings class, but as I found in the documentation: 

On Windows, for 32-bit programs running in WOW64 mode, settings are stored in the following registry path: HKEY_LOCAL_MACHINE\Software\WOW6432node\MySW

Is there a way to override it and write to: HKEY_LOCAL_MACHINE\Software\MySW directly?

Clarification:

The application is writing to the registry, the keys written are to be used by other application, which I cannot know if running on 64 or 32 bit mode.

I know it is possible in C#, so it must be possible in C++.


回答1:


See this article on MSDN:

32-bit and 64-bit Application Data in the Registry

It appears that using some of the Win32 API you might be able to change how this behaves. Although I'm not sure why the default behavior won't work for you.




回答2:


I suppose that if you want to do it in Qt then this would be the most appropriate way:


[ Source: http://doc.qt.digia.com/4.7/qsettings.html#accessing-the-windows-registry-directly ]

Accessing the Windows Registry Directly On Windows, QSettings lets you access settings that have been written with QSettings (or settings in a supported format, e.g., string data) in the system registry. This is done by constructing a QSettings object with a path in the registry and QSettings::NativeFormat.
For example:
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", QSettings::NativeFormat);

All the registry entries that appear under the specified path can be read or written through the QSettings object as usual (using forward slashes instead of backslashes).
For example:
settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);



来源:https://stackoverflow.com/questions/11598466/qt-write-to-registry-32-64-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!