Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [QBS] How to override product properties?
QtWS25 Last Chance

[QBS] How to override product properties?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
qbsproductpropertyoverride
6 Posts 2 Posters 993 Views
  • 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.
  • C Offline
    C Offline
    Clint Westwood
    wrote on 29 Jul 2021, 15:23 last edited by Clint Westwood
    #1

    Suppose there is a product (library) which build process can be customised, and there is some property which is supposed to be set outside of product itself:

    // Library.qbs
    
    StaticLibrary
    {
        property string test_property: “something”
    }
    

    How do I change test_property’s value outside of Library.qbs?

    For Projects there is SubProject item, which lets to do that, but it does not work for Products.

    A workaround would be to wrap Product in Project:

    // Library.qbs
    
    Project
    {
        property string test_property: “something”
        StaticLibrary
        {
           property string test_property: project.test_property
        }
    }
    

    Then this could be done:

    // Build.qbs
    
    Project
    {
        SubProject
        {
            filePath: “Library.qbs”
            Properties { test_property: “something else” }
        }
    }
    

    But that does not feel right at all.

    It appears another way is to do it is to use QBS from command line, but I work with Qt Creator, so I guess this is not an option in my case.

    Is there a better mechanism to override properties? Ideally something similar to what SubProject does.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 31 Jul 2021, 13:38 last edited by kuzulis
      #2

      See documentation: https://doc.qt.io/qbs/language-introduction.html#overriding-property-values-from-the-command-line

      StaticLibrary
      {
          name: "my-library"
          property string test_property: “something”
      }
      

      like this:

      $qbs products.my-library.test_property:"foo"
      

      You can pass this also and in QtCreator "Qbs build step" properties field of your project, just as products.my-library.test_property:"foo".

      PS: You can also ask a Qbs question on a Discord server: https://discord.gg/ZXT6YKq (right now all Qbs developers and users live there). ;)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Clint Westwood
        wrote on 1 Aug 2021, 15:15 last edited by
        #3

        Thank you, what you suggested does work, but I am not sure this is quite what I am looking for.

        As far as I understand, I will have to manually enter all the product properties that I need to override in the “QBS build steps” submenu each time I reinstall Qt Creator / Operating System or move project to a new machine.

        Is there any way to alter these build steps from within the project file itself? I am currently enjoying the fact that I can just open my project file in Qt Creator and immediately build it without having to manually set anything up, I would like to keep it that way.

        When talking about “QBS build steps”, you were referring to this article, correct?

        Also thanks for that discord link, I will make sure to ask my next questions there as well.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on 1 Aug 2021, 18:40 last edited by kuzulis 8 Jan 2021, 19:03
          #4

          @Clint-Westwood said in [QBS] How to override product properties?:

          Is there any way to alter these build steps from within the project file itself?

          AFAIK, No

          I need to override in the “QBS build steps” submenu each time I reinstall Qt Creator / Operating System or move project to a new machine.

          Well, these settings are stored in the *.qbs.user file which is created by QtCreator automatically.

          When talking about “QBS build steps”, you were referring to this article, correct?

          Yes.

          UPD: Alternativelly, you can use the VSCode IDE with the Qbs extension instead of the QtCreator. In the version 1.0.3 was added support for the qbs-configurations.json file in which you can specify the desired build configurations with the overridden properties. ;)

          C 1 Reply Last reply 1 Aug 2021, 21:32
          0
          • K kuzulis
            1 Aug 2021, 18:40

            @Clint-Westwood said in [QBS] How to override product properties?:

            Is there any way to alter these build steps from within the project file itself?

            AFAIK, No

            I need to override in the “QBS build steps” submenu each time I reinstall Qt Creator / Operating System or move project to a new machine.

            Well, these settings are stored in the *.qbs.user file which is created by QtCreator automatically.

            When talking about “QBS build steps”, you were referring to this article, correct?

            Yes.

            UPD: Alternativelly, you can use the VSCode IDE with the Qbs extension instead of the QtCreator. In the version 1.0.3 was added support for the qbs-configurations.json file in which you can specify the desired build configurations with the overridden properties. ;)

            C Offline
            C Offline
            Clint Westwood
            wrote on 1 Aug 2021, 21:32 last edited by
            #5

            @kuzulis said in [QBS] How to override product properties?:

            Well, these settings are stored in the *.qbs.user file which is created by QtCreator automatically.

            But this file is not transferable across machines as far as I remember (I delete it every time I move my project elsewhere). So after moving project to another environment I would still have to set all the properties manually again I suppose.

            UPD: Alternativelly, you can use the VSCode IDE with the Qbs extension instead of the QtCreator. In the version 1.0.3 was added support for the qbs-configurations.json file in which you can specify the desired build configurations with the overridden properties. ;)

            That looks like another good idea, I always wanted to try this IDE out ever since that QBS extension had been released, but I am just not bold enough to switch from Qt Creator in the middle of development of my project unfortunately.

            There has got to be some way to do it from QBS file, if it can be done from the command line then all the functionality is already there.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuzulis
              Qt Champions 2020
              wrote on 2 Aug 2021, 10:51 last edited by
              #6

              @Clint-Westwood said in [QBS] How to override product properties?:

              here has got to be some way to do it from QBS file

              I'm not sure. But you may ask the question on the discord chat, because there are more peoples. ;)

              1 Reply Last reply
              0

              3/6

              1 Aug 2021, 15:15

              • Login

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