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. Dynamically exchange component implementations

Dynamically exchange component implementations

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 2.1k 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.
  • S Offline
    S Offline
    Schluchti
    wrote on last edited by
    #1

    Hi,

    first of all, sorry for the confusing thread title.

    As the Qt 5.8 Beta is now out, I want to try to exchange some of my own implementations with built in components. For example: Until 5.8, there wasn't a rounded button available, so I created my own RoundedButton.qml, but as Qt 5.8 has now a RoundButton, I want to use that. However, as Qt5.8 is still Beta, I want to have the possibility to easily switch back to Qt 5.7, if something doesn't work.

    If it would be C++, I would be doing something like this in my RoundedButton.qml:

    #if QT_BUILD_VERSION > 5.7
    import QtQuick.Controls 2.1
    #else
    import QtQuick.Controls 2.0
    #endif
    
    #if QT_BUILD_VERSION > 5.7
    // use the RoundButton implementation from Qt 5.8
    #else
    // use my own implementation
    #endif
    

    Is that also somehow possible in QML?

    Want to read more about Qt?

    https://gympulsr.com/blog/qt/

    Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

    raven-worxR 1 Reply Last reply
    0
    • S Schluchti

      Hi,

      first of all, sorry for the confusing thread title.

      As the Qt 5.8 Beta is now out, I want to try to exchange some of my own implementations with built in components. For example: Until 5.8, there wasn't a rounded button available, so I created my own RoundedButton.qml, but as Qt 5.8 has now a RoundButton, I want to use that. However, as Qt5.8 is still Beta, I want to have the possibility to easily switch back to Qt 5.7, if something doesn't work.

      If it would be C++, I would be doing something like this in my RoundedButton.qml:

      #if QT_BUILD_VERSION > 5.7
      import QtQuick.Controls 2.1
      #else
      import QtQuick.Controls 2.0
      #endif
      
      #if QT_BUILD_VERSION > 5.7
      // use the RoundButton implementation from Qt 5.8
      #else
      // use my own implementation
      #endif
      

      Is that also somehow possible in QML?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Schluchti
      actually the QML versioning system is perfect for such cases.
      Create a 2.0 version of your button. For 2.0 the minimum requirement simply is Qt 5.8 then.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schluchti
        wrote on last edited by
        #3

        @raven-worx many thanks for your answer!

        If I understand you correctly, I need to do the following:

        • create a new version (2.0) of my component that depends on Qt5.8
        • import version 2.0 of my component, whenever I want to use the component. If the application is built with Qt5.7, it automatically falls back to the 1.0 implementation, as the requirements are not met.

        Is that correct?

        And another question: How can I make my component depend on Qt5.8?

        Thanks a lot!

        Have a nice day,
        Bernhard

        Want to read more about Qt?

        https://gympulsr.com/blog/qt/

        Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

        raven-worxR 1 Reply Last reply
        0
        • S Schluchti

          @raven-worx many thanks for your answer!

          If I understand you correctly, I need to do the following:

          • create a new version (2.0) of my component that depends on Qt5.8
          • import version 2.0 of my component, whenever I want to use the component. If the application is built with Qt5.7, it automatically falls back to the 1.0 implementation, as the requirements are not met.

          Is that correct?

          And another question: How can I make my component depend on Qt5.8?

          Thanks a lot!

          Have a nice day,
          Bernhard

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Schluchti said in Dynamically exchange component implementations:

          it automatically falls back to the 1.0 implementation, as the requirements are not met.

          no, in that case you would get a QML error that the type is not available.

          What are you exactly trying to do?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Schluchti
            wrote on last edited by
            #5

            Ah, I see.

            Ideally it would be great, if Qt takes care of which component is going to be used. So if I use the Qt 5.7 Kit, it would be great, if my own implementation of the RoundedButton is used. If I create a Qt application with the Qt 5.8 Kit, it would be great if the RoundButton of Qt 5.8 is used.

            Want to read more about Qt?

            https://gympulsr.com/blog/qt/

            Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

            raven-worxR 1 Reply Last reply
            0
            • S Schluchti

              Ah, I see.

              Ideally it would be great, if Qt takes care of which component is going to be used. So if I use the Qt 5.7 Kit, it would be great, if my own implementation of the RoundedButton is used. If I create a Qt application with the Qt 5.8 Kit, it would be great if the RoundButton of Qt 5.8 is used.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Schluchti
              whats the use case with switching Qt versions?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Schluchti
                wrote on last edited by
                #7

                @raven-worx My use case would be to test features of alpha/beta releases, without breaking the functionality of the existing application. I really like the idea of testing a new Qt release early, but I want to avoid that I exchange a lot of self written components with built in components and then find out that something doesn't work as expected. In that case it would be great to switch back to the stable release, without manually changing the relevant code parts. I know, that I could also accomplish this by creating a new branch of my application, but I am curious if I can accomplish this also somehow with Qt directly.

                Want to read more about Qt?

                https://gympulsr.com/blog/qt/

                Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

                raven-worxR 1 Reply Last reply
                0
                • S Schluchti

                  @raven-worx My use case would be to test features of alpha/beta releases, without breaking the functionality of the existing application. I really like the idea of testing a new Qt release early, but I want to avoid that I exchange a lot of self written components with built in components and then find out that something doesn't work as expected. In that case it would be great to switch back to the stable release, without manually changing the relevant code parts. I know, that I could also accomplish this by creating a new branch of my application, but I am curious if I can accomplish this also somehow with Qt directly.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @Schluchti
                  ok when it's just for testing then you could do the switch in C++ when creating the QQmlEngine and load a 1.0 and 2.0 base file for example

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Schluchti
                    wrote on last edited by
                    #9

                    @raven-worx Many thanks, I'll look into this.

                    Want to read more about Qt?

                    https://gympulsr.com/blog/qt/

                    Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

                    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