Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is there a QT project-specific configuration file available ? There is the .pro.user file, but that can't go cross platform.



  • I am basically trying to add a language configuration into the configuration file, based on which the UI language should change is the idea. I was looking at .pro.user for a while, planned on adding the language setting in the XML but the file gets overwritten even though thats checked into version control and pulled to a different environment.
    Another method I tried was to create a configuration file of my own and had a couple configs in there and was reading stuff off of that, this isn't a great idea because it adds another file into the project.
    I want to know and understand if theres a file that could be shared across different OSes and platforms, would be great if the file already exists and if I could just add some configs into that. I am very new to QT and this is my first post on the forum


  • Lifetime Qt Champion

    @Tryhard said in Is there a QT project-specific configuration file available ? There is the .pro.user file, but that can't go cross platform.:

    I was looking at .pro.user for a while, planned on adding the language setting in the XML but the file gets overwritten even though thats checked into version control and pulled to a different environment.

    No, that is not allowed. The .pro.user file should never be shared.

    It is possible to share some of the settings, see https://doc.qt.io/qtcreator/creator-sharing-project-settings.html but that is very limited.

    Can you elaborate what your goal is? I think the UI language is something for run time, not for compile time.

    Regards


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Your request is not quite clear, what language are you talking about ?

    In any case, the .pro.user file should not be checked in version control. It's specific to the machine you are using to build your project.



  • Hey, thank you so much for your replies. Sorry I wasn't clear at all.
    So my goal is, my UI file has a couple labels, they would have to be displayed in the language that has been read in the configuration file. The configuration file would have a 'Language' key and the values would be EN (English), SP (Spanish) and FN (French). My plan was to have the read the config file in the constructor of my main file and apply some translations onto it during runtime.
    @aha_1980 that is an interesting way to share settings , thank you for that. I could just have the language setting in there, is definitely close to a solution


  • Lifetime Qt Champion

    Are you aware of QTranslator ?



  • Yeah I did use QTranslator, added the translatable strings and their respective translations onto QTLinguist and generated QMLs. This was supposed to be the second step of the process, first step was to read the language setting off of a config file and then use QTranslator to translate.


  • Lifetime Qt Champion

    Hi @Tryhard,

    again: the pro.shared is for compile/build time.

    What you are looking for is to change the language at runtime. You can use QSettings for that.

    Regards



  • @Tryhard said in Is there a QT project-specific configuration file available ? There is the .pro.user file, but that can't go cross platform.:

    Yeah I did use QTranslator, added the translatable strings and their respective translations onto QTLinguist and generated QMLs

    Please keep in mind that creating a "translatable" Qt application is a two phase process:

    1. during build/compilation
    2. at runtime

    For #1, you enclose all the strings that should be translated with tr() function. Then you run command lupdate, which extracts all strings into .ts files (depending on the languages you specify in property translations in your .pro file). You open the .ts file(s) with Qt Linguist and translate the string into the appropiate language(s). Finally run lrelease to create .qm files from the .ts files

    For #2, your application creates a QTranslator object by loading the translation file (.qm) you want/need your application to use.
    The display language can be selected "statically", i.e. at app startup by checking the system locale setting for instance, or by reading the language to use from a QSettings file.
    Or it can be selected "dynamically" multiple times as the Qt app is running (from a menu for instance) and every language change means you need to uninstall one QTranslator and load another one for the new selected language



  • Hey thank you so much for your replies, I think QSettings is a great option. I did my bit of research but I'd love to know more. I feel there is one downside to this, lets take this scenario, if I was to deploy this application to people in France, lets assume the default language setting is English and their build should have French and they are just consumers, they just want the APK, in that case I'd have to change the setting in the code and ship the build right ? In other words, is there a way to manage the language setting dynamically ? Having a setting in the UI itself seems like a way to do it, are there any other ways.
    All in all, I'd say I've got my solution - QSettings. Thanks again for all your replies <3


  • Lifetime Qt Champion

    @Tryhard

    how about query the system language at first start with https://doc.qt.io/qt-5/qlocale.html#system and choose the default according to that?

    Should be sensible for most customers.

    Regards



  • Yep that should do it !! Thanks y'all !



  • @Tryhard said in Is there a QT project-specific configuration file available ? There is the .pro.user file, but that can't go cross platform.:

    Yep that should do it !! Thanks y'all !

    Are you calling your issue solved? If so, please don't forget to mark your post as such! Thanks.


Log in to reply