Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is there a QT project-specific configuration file available ? There is the .pro.user file, but that can't go cross platform.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 4 Posters 999 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tryhard
    wrote on last edited by Tryhard
    #1

    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

    aha_1980A 1 Reply Last reply
    0
    • T Tryhard

      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

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • T Offline
          T Offline
          Tryhard
          wrote on last edited by Tryhard
          #4

          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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Are you aware of QTranslator ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • T Offline
              T Offline
              Tryhard
              wrote on last edited by Tryhard
              #6

              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.

              aha_1980A Pablo J. RoginaP 2 Replies Last reply
              0
              • T Tryhard

                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.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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

                Qt has to stay free or it will die.

                1 Reply Last reply
                2
                • T Tryhard

                  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.

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by Pablo J. Rogina
                  #8

                  @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

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  2
                  • T Offline
                    T Offline
                    Tryhard
                    wrote on last edited by
                    #9

                    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

                    aha_1980A 1 Reply Last reply
                    1
                    • T Tryhard

                      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

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      2
                      • T Offline
                        T Offline
                        Tryhard
                        wrote on last edited by
                        #11

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

                        Pablo J. RoginaP 1 Reply Last reply
                        0
                        • T Tryhard

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

                          Pablo J. RoginaP Offline
                          Pablo J. RoginaP Offline
                          Pablo J. Rogina
                          wrote on last edited by
                          #12

                          @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.

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved