Qt World Summit: Register Today!

QSettings file path

  • I am looking at a Qt project. I know that QCoreApplication provides an event loop. Below it sets the organization name and application name:

    @ app = new QCoreApplication(argc, argv);
    int rc = app->exec();@

    Now below is what confuses me a little. When we initialize a QSettings instance, I know that the QSettings constructor is invoked, which constructs a QSettings object for accessing settings of the application, such as the organization name and application name. But then below that we make a call to this method fileName(). Now this returns a path where settings are stored. My question is how did it generate this path?

    @QSettings settings;
    settings.fileName() // home/guarddoguser/.config/GuardDog/MyGateway.conf@

    I know that GuardDog is the organization name and MyGateway is the application name. But how did it know to add a .config directory and attach a .conf to the application name? Is this something that QSettings does behind the scenes, or is there something else going on?

  • Lifetime Qt Champion


    Since you don't set anything specifically, you are using the default OS specific settings backend that does this for you. On Windows you'll be using the registry and on OS X a plist file located in ~/Library/Preferences

Log in to reply