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. preprocessing in QML?
Forum Updated to NodeBB v4.3 + New Features

preprocessing in QML?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 5 Posters 2.6k Views 1 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by
    #1

    Hi,
    is there any ways to use #ifdef on macros defined in the pro file?
    so to have a single QML file that could have variants depending on the conf.
    I'm thinking on a simple example: easily change my Items from a background image to a simple colour or gradient.

    jsulmJ 1 Reply Last reply
    0
    • mbruelM mbruel

      Hi,
      is there any ways to use #ifdef on macros defined in the pro file?
      so to have a single QML file that could have variants depending on the conf.
      I'm thinking on a simple example: easily change my Items from a background image to a simple colour or gradient.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mbruel As far as I know not. But you could use different QML files depending on the condition.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        it's to avoid to duplicate code...
        maybe in JS it's possible to do something similar using a global variable (from JS or C++) but probably more an hassle than a simple #ifdef

        J.HilkJ 1 Reply Last reply
        0
        • mbruelM mbruel

          it's to avoid to duplicate code...
          maybe in JS it's possible to do something similar using a global variable (from JS or C++) but probably more an hassle than a simple #ifdef

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @mbruel last thing I heard, was that we get something along those lines with Qt6 🤷‍♂️


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          mbruelM 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @mbruel last thing I heard, was that we get something along those lines with Qt6 🤷‍♂️

            mbruelM Offline
            mbruelM Offline
            mbruel
            wrote on last edited by
            #5

            @J-Hilk
            that would be great. Preprocessing statements are really a strength of C++ over all the over languages (even if you can find some stuff in java but not native).
            it allows to maintain one single main production branch that can easily be tweaked depending on the client, device or even just you mood :p

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              I do this for QT_DEBUG:

                      #ifdef QT_DEBUG
                      engine->rootContext()->setContextProperty("QT_DEBUG", true);
                      #else
                      engine->rootContext()->setContextProperty("QT_DEBUG", false);
                      #endif
              

              I use this to change the behavior and hide dev tools from the end user. It is not automatic though.

              mbruelM 1 Reply Last reply
              0
              • fcarneyF fcarney

                I do this for QT_DEBUG:

                        #ifdef QT_DEBUG
                        engine->rootContext()->setContextProperty("QT_DEBUG", true);
                        #else
                        engine->rootContext()->setContextProperty("QT_DEBUG", false);
                        #endif
                

                I use this to change the behavior and hide dev tools from the end user. It is not automatic though.

                mbruelM Offline
                mbruelM Offline
                mbruel
                wrote on last edited by
                #7

                @fcarney
                how do you access your "QT_DEBUG" variable in QML or JS?
                what I'm asking for would be to <define>/<don't define> Items using some kind of preprocessing, not later in JavaScript using the visible property. Do you see what I mean? It's much more efficient as there are no dynamic test, it would be "pre-compiled"... or just escaping for an interpreted language.

                1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by fcarney
                  #8

                  Use a Loader
                  I see what you mean. There is nothing to define except maybe some kind of loading/dynamic JS.
                  You just use QT_DEBUG as a variable in your code. It is a property available globally.

                  1 Reply Last reply
                  0
                  • fcarneyF Offline
                    fcarneyF Offline
                    fcarney
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • GrecKoG Offline
                      GrecKoG Offline
                      GrecKo
                      Qt Champions 2018
                      wrote on last edited by
                      #10

                      Not exactly the same but you could use QQmlFileSelector to load different files depending on some condition.

                      You would have a Foobar.qml loaded normally but in debug mode +debug/Foorbar.qml would be loaded instead.

                      1 Reply Last reply
                      0

                      • Login

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