Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to save a file path in a single entry (Windows Registry by using QSettings?
A Former User last edited by
I want to enable the Windows XP Compatibility Mode in my app by clicking in an action in the app. The steps are easy:
- Acces to the Windows Registry
- Go to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\
- Add a new entry with the path of the exe file. Finally, set "WINXPSP3" as value.
- The next time, the app will be launched in this mode.
Now, im trying to implement it on Qt by using QSettings:
- First, get the current file path of the exe file
const QString appPath = QCoreApplication::applicationFilePath();
- Go in QSetting to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\
const QString regPath = QStringLiteral("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers\\"); QSettings* reg = new QSettings(regPath, QSettings::NativeFormat);
- Now Add the entry:
What is the problem?
QT didn't create an entry with this value. Qt create multiple subgroups depending of the directory tree. Example: C:\Program Files (x86)\Example\example.exe
"C:" -> "Program Files (x86)" -> "Example" -> "example.exe" (value WINXPSP3).
But i want:
"C:\Program Files (x86)\Example\example.exe" (value WINXPSP3)
Anyone, could help me?
Sorry for my poor english.
the_ last edited by the_
As mentioned in the documentation a single "\" or "/" indicates a subkey separator. You could try to use "\\" instead of "\".