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. QML Conditional Based on Kit

QML Conditional Based on Kit

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 880 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.
  • D Offline
    D Offline
    Dane 0
    wrote on last edited by
    #1

    I would like to specify a custom gstreamer pipeline for my MediaPlayer when running on embedded Linux (but not when running on desktop Linux). I can't use Qt.platform.os as this is "linux" for both. How can I detect the Kit (or any other parameter making it possible to detect the embedded Linux target) in QML?

    sierdzioS 1 Reply Last reply
    0
    • D Dane 0

      I would like to specify a custom gstreamer pipeline for my MediaPlayer when running on embedded Linux (but not when running on desktop Linux). I can't use Qt.platform.os as this is "linux" for both. How can I detect the Kit (or any other parameter making it possible to detect the embedded Linux target) in QML?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Dane-0 I think you need to get that information in C++ and then pass it to QML.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dane 0
        wrote on last edited by
        #3

        @sierdzio Thanks! How would I do that? I'm currently trying to get a define added under the CMake configuration using something like
        -DQMAKE_CXXFLAGS:STRING='-DEMBEDDED'
        or
        -DCMAKE_CXXFLAGS:STRING='-DEMBEDDED'
        however I haven't been able to get this to work as yet.

        sierdzioS 1 Reply Last reply
        0
        • D Dane 0

          @sierdzio Thanks! How would I do that? I'm currently trying to get a define added under the CMake configuration using something like
          -DQMAKE_CXXFLAGS:STRING='-DEMBEDDED'
          or
          -DCMAKE_CXXFLAGS:STRING='-DEMBEDDED'
          however I haven't been able to get this to work as yet.

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by sierdzio
          #4

          @Dane-0 there are many ways to do it, personally I'd probably go with something like this:

          In some CMakeLists.txt:

          option(IS_EMBEDDED "Enable embedded mode" OFF)
          
          if (IS_EMBEDDED)
              message("Building embedded")
              add_definitions(-DEMBEDDED)
          endif()
          

          You can call cmake with cmake -DIS_EMBEDDED=ON or just select that option in Qt Creator's Project->Build settings.

          Then, in C++ you can do this:

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

          Lastly, in QML:

          Text {
              text: isEmbedded ? "Embedded!" : "Desktop :-("
          }
          

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dane 0
            wrote on last edited by
            #5

            @sierdzio Thanks again! :-)
            I am new to this so please excuse me if these questions are "silly":

            In some CMakeLists.txt:

            There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?

            You can call cmake with cmake -DIS_EMBEDDED=ON or just select that option in Qt Creator's Project->Build settings.

            Where would this option be selected? I'm looking under "Projects" (mode selected on the left), but don't immediately see "options" to be selected.

            I follow with everything after that, just struggling to get the actual #define implemented.

            sierdzioS 1 Reply Last reply
            0
            • D Dane 0

              @sierdzio Thanks again! :-)
              I am new to this so please excuse me if these questions are "silly":

              In some CMakeLists.txt:

              There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?

              You can call cmake with cmake -DIS_EMBEDDED=ON or just select that option in Qt Creator's Project->Build settings.

              Where would this option be selected? I'm looking under "Projects" (mode selected on the left), but don't immediately see "options" to be selected.

              I follow with everything after that, just struggling to get the actual #define implemented.

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @Dane-0 said in QML Conditional Based on Kit:

              @sierdzio Thanks again! :-)
              I am new to this so please excuse me if these questions are "silly":

              In some CMakeLists.txt:

              There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?

              If you have a .pro file then you are NOT using cmake but qmake.

              So, with qmake this will be a bit different. In your .pro:

              is-embedded {
                DEFINES += EMBEDDED
              }
              

              Then call qmake with:

              qmake CONFIG+=is-embedded
              

              C++ and QML stay the same.

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dane 0
                wrote on last edited by
                #7

                Brilliant, that works, thanks! :-)

                I ended up with:

                is_embedded {
                  DEFINES += IS_EMBEDDED
                }
                

                in the .pro

                and then

                CONFIG+=is_embedded
                

                under Projects -> Build (for relevant kit) -> Build Steps -> Additional arguments.

                Thanks again @sierdzio !

                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