Qt - How to save a configuration file on multiple platforms

前端 未结 4 992
一生所求
一生所求 2021-01-20 15:35

I\'m writing a Qt application that needs to save some settings to the user\'s configuration directory.

I\'ve come up with the following code to get this folder:

4条回答
  •  Happy的楠姐
    2021-01-20 16:30

    Yes, this is supposed to be an easy task - but you're not supposed to hard-code paths. You should use the native APIs on win/mac, and an enviroment variable on most newer unix-like. Of course, Qt helps you do this cross-platform.

    Follow Tibur's suggestion and use QSettings if it's configuration data for your Qt app. You can also get the config directory by using the appropriate QT api.

    QT4: QDesktopServices::storageLocation(QDesktopServices::DataLocation)
    QT5: QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)

提交回复
热议问题