How to save a file path in a single entry (Windows Registry by using QSettings?

  • 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:
        reg->setValue(appPath, "WINXPSP3");

    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.

  • @mojito

    As mentioned in the documentation a single "\" or "/" indicates a subkey separator. You could try to use "\\" instead of "\".

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.