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. Property Alias and runtime loaded QML-Items
QtWS25 Last Chance

Property Alias and runtime loaded QML-Items

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlproperty aliasstackview
4 Posts 2 Posters 2.7k 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.
  • J Online
    J Online
    J.Hilk
    Moderators
    wrote on 7 Nov 2017, 06:44 last edited by
    #1

    Hello everyone,

    I came across something I'm not quite sure how to handle and hopefully someone can shine some light on this.

    The situation:
    Currently I design a couple differen small objects, each one consists mainly of a StackView for management and basic animation. The StackView than loads the appropriate Display and Input Objects.

    This is a simplyfied structure:

    Item {
        id:root
        property alias obj1Alias: obj1.text
        property alias obj2Alias: obj2.value
        property alias obj3Alias: obj3.value
    
        StackView{
            id: view
            anchors.fill:parent
            focus: true
    
            initialItem: Obj1{id: obj1; onClicked: view.push(obj2)}
    
            Obj2{id:obj2;onClicked: view.push(obj3)}
            Obj3{id:obj3;onClicked: view.push(obj1)}
         }
    }
    

    I do this to propagate the changed values/texts to the parent that than does stuff with the values and ultimately updates a c++ class.

    My Question:

    • I've been told, to increase performance one should use view.push(Qt.resolvedUrl("MyObject.qml")). But I'm not sure how I would make an property alias to a dynamically loaded qml-file.

    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.

    S 1 Reply Last reply 7 Nov 2017, 13:38
    0
    • J J.Hilk
      7 Nov 2017, 06:44

      Hello everyone,

      I came across something I'm not quite sure how to handle and hopefully someone can shine some light on this.

      The situation:
      Currently I design a couple differen small objects, each one consists mainly of a StackView for management and basic animation. The StackView than loads the appropriate Display and Input Objects.

      This is a simplyfied structure:

      Item {
          id:root
          property alias obj1Alias: obj1.text
          property alias obj2Alias: obj2.value
          property alias obj3Alias: obj3.value
      
          StackView{
              id: view
              anchors.fill:parent
              focus: true
      
              initialItem: Obj1{id: obj1; onClicked: view.push(obj2)}
      
              Obj2{id:obj2;onClicked: view.push(obj3)}
              Obj3{id:obj3;onClicked: view.push(obj1)}
           }
      }
      

      I do this to propagate the changed values/texts to the parent that than does stuff with the values and ultimately updates a c++ class.

      My Question:

      • I've been told, to increase performance one should use view.push(Qt.resolvedUrl("MyObject.qml")). But I'm not sure how I would make an property alias to a dynamically loaded qml-file.
      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 7 Nov 2017, 13:38 last edited by
      #2

      @J.Hilk said in Property Alias and runtime loaded QML-Items:

      I've been told, to increase performance one should use view.push(Qt.resolvedUrl("MyObject.qml")). But I'm not sure how I would make an property alias to a dynamically loaded qml-file.

      Do you experience any performance issues? If no, they you can safely disregard that hint. The performance improvement in question comes from dynamically allocating the QML component when push() is called, instead of constructing it at application startup. But there are other ways to achieve same goal, too (using a Loader, for example, which should allow you to keep an alias).

      If yes, I would first look into optimizing the way you use the stack - I think in Obj3 you should pop() back to obj1 instead of pushing it again. I'm not sure, though.

      Regarding your question: you may be able to get the alias to work using the parameters dictionary described in the docs http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html#push-method I'm not sure if it will work, though.

      (Z(:^

      J 1 Reply Last reply 8 Nov 2017, 06:17
      1
      • S sierdzio
        7 Nov 2017, 13:38

        @J.Hilk said in Property Alias and runtime loaded QML-Items:

        I've been told, to increase performance one should use view.push(Qt.resolvedUrl("MyObject.qml")). But I'm not sure how I would make an property alias to a dynamically loaded qml-file.

        Do you experience any performance issues? If no, they you can safely disregard that hint. The performance improvement in question comes from dynamically allocating the QML component when push() is called, instead of constructing it at application startup. But there are other ways to achieve same goal, too (using a Loader, for example, which should allow you to keep an alias).

        If yes, I would first look into optimizing the way you use the stack - I think in Obj3 you should pop() back to obj1 instead of pushing it again. I'm not sure, though.

        Regarding your question: you may be able to get the alias to work using the parameters dictionary described in the docs http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html#push-method I'm not sure if it will work, though.

        J Online
        J Online
        J.Hilk
        Moderators
        wrote on 8 Nov 2017, 06:17 last edited by
        #3

        Hi @sierdzio ,thanks for the answer.

        Do you experience any performance issues?

        In this case, not jet. But I thought, If I'm basically learning a "new language" than I better avoid adopting bad habits, if I can.
        It's something that was said during the QTWS17 by Jesper Pedersen, I thought he ought to know, what he's talking about x)

        But there are other ways to achieve the same goal, too (using a Loader, for example, which should allow you to keep an alias).

        thanks I'll look into the Loader a bit more. I know it exists and you can use it to sequentially load your UI to make it accessibility faster, but thats about it.

        I think in Obj3 you should pop() back to obj1 instead of pushing it again

        You're of course correct, it was an abstract example of what I'm trying to do. I would use

        Obj3{id:obj3;onClicked: view.pop(obj1)}
        

        to get back down to the first obj.

        I'm however not sure what you mean with parameters dictionary.


        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.

        S 1 Reply Last reply 8 Nov 2017, 07:06
        0
        • J J.Hilk
          8 Nov 2017, 06:17

          Hi @sierdzio ,thanks for the answer.

          Do you experience any performance issues?

          In this case, not jet. But I thought, If I'm basically learning a "new language" than I better avoid adopting bad habits, if I can.
          It's something that was said during the QTWS17 by Jesper Pedersen, I thought he ought to know, what he's talking about x)

          But there are other ways to achieve the same goal, too (using a Loader, for example, which should allow you to keep an alias).

          thanks I'll look into the Loader a bit more. I know it exists and you can use it to sequentially load your UI to make it accessibility faster, but thats about it.

          I think in Obj3 you should pop() back to obj1 instead of pushing it again

          You're of course correct, it was an abstract example of what I'm trying to do. I would use

          Obj3{id:obj3;onClicked: view.pop(obj1)}
          

          to get back down to the first obj.

          I'm however not sure what you mean with parameters dictionary.

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 8 Nov 2017, 07:06 last edited by
          #4

          @J.Hilk said in Property Alias and runtime loaded QML-Items:

          I'm however not sure what you mean with parameters dictionary.

          Oh sorry, wrong word :-) I've meant this from the link I provided:

          properties: a list of QML properties that should be assigned to the item upon push. These properties will be copied into the item when it is loaded (in case of a component or URL), or when it becomes the current item for the first time (normally upon push).

          Another possibility would be to use some global context property (added in C++) which your whole app can access. Then you don't need to worry about when and how elements are loaded.

          In this case, not jet. But I thought, If I'm basically learning a "new language" than I better avoid adopting bad habits, if I can.

          It is not necessarily a bad habit. It is a trade-off:

          • you load all QML code at application startup - startup is longer (slightly - parsing QML is extremely fast), then all works fast at runtime (or possibly it instantiates components on push(). It definitely does that if you encapsulate ObjX in Component, I'm not sure if it also applies to the way you've done it)
          • or you load by Loader / URL at runtime - startup is faster, but then you will need some time to load the QML file at runtime when user wants to access given stack page

          (Z(:^

          1 Reply Last reply
          0

          1/4

          7 Nov 2017, 06:44

          • Login

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