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. Dynamic component makes multiple components !!! in qml
Forum Updated to NodeBB v4.3 + New Features

Dynamic component makes multiple components !!! in qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 349 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.
  • Q Offline
    Q Offline
    qAminzzz
    wrote on last edited by qAminzzz
    #1

    hi, im using pyqt6 and i have a problem.
    i used below code to make a component dynamically

        property var dtaComp: Qt.createComponent("Data.qml")
        property var dtaObj: dtaComp.createObject(crt_MainFrame,
                                        {
                                            x: (crt_frmLeft.width < 250) ? 59 : 259,
                                            width: (crt_frmLeft.width < 250) ? 993 : 743,
                                            y: 109,
                                            height: crt_MainFrame.height - 110,
                                        }
                                        )
    

    and in Data.qml :

        Component.onCompleted:
        {
            print("******* CREATED *******")
        }
    

    when i run this i got this message for 4 time:
    '' ******* CREATED ******* ''
    i don't know why it is happened

    i just wanna make Data class and show this dynamically

    i don't really know what is wrong i'm confused
    thanks for any help

    • i commented this code and there is no any CREATED message anymore. so we know problem is in that code

    solution:

    in last god helped me (:
    i understood that when crt_frmLeft.width or height changed my object class also will be make again ( i don't know exactly ) so becarefull to don't bind this object properties

    can tell me anybody why that is like this? this is sooooo bad ):

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Why are you using dynamic creation here?
      Wouldn't the following do what you need?

      property Data dtaObj: Data {
          x: (crt_frmLeft.width < 250) ? 59 : 259
          width: (crt_frmLeft.width < 250) ? 993 : 743
          y: 109
          height: crt_MainFrame.height - 110
      } 
      

      As for the original question, it's just how QML and property bindings work. If you are accessing a property in a declarative binding and this property changes, the binding is reevaluated. Here it means calling dtaComp.createObject again. That's what makes QML so good, but you have to think declaratively to make the most use out of it.

      Q 1 Reply Last reply
      1
      • GrecKoG GrecKo

        Why are you using dynamic creation here?
        Wouldn't the following do what you need?

        property Data dtaObj: Data {
            x: (crt_frmLeft.width < 250) ? 59 : 259
            width: (crt_frmLeft.width < 250) ? 993 : 743
            y: 109
            height: crt_MainFrame.height - 110
        } 
        

        As for the original question, it's just how QML and property bindings work. If you are accessing a property in a declarative binding and this property changes, the binding is reevaluated. Here it means calling dtaComp.createObject again. That's what makes QML so good, but you have to think declaratively to make the most use out of it.

        Q Offline
        Q Offline
        qAminzzz
        wrote on last edited by
        #3

        @GrecKo thank you for your answer.
        actually i did'nt know this way to make my component dinamically.
        i learned this thing about binding and now i know. thanks

        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