Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Display Array of Objects in Column



  • So I have A Column like this:

        SystemInformation{
            id: sysinfo
        }
    
        Column{
    
    //...
            CPUUtilizationDisplay{
                width: root.elementWidth
                height: root.elementHeight
    
                value: sysinfo.cpuUtilizationInPercent
            }
            CoreUtilizationDisplay{
                width: root.elementWidth
                height: root.elementHeight
                core: 1 
    //...
            }
            CoreUtilizationDisplay{
                width: root.elementWidth
                height: root.elementHeight
                core: 2
    //...
            }
    
    //...
    }
    

    Now my problem is I only now after startup how many CoreUtilizationDisplay Objects I need when the sysinfo can tell me how many cores the system has. So the count of Elements of type CoreUtilizationDisplay is only nowable at run time. How can I achieve to display them?

    Sysinfo gives me an array of doubles and I need to create for each element one CoreUtilizationDisplay.



  • Could solve it myself:

        Repeater{
            model: sysinfo.coreUtilizationsInPercent.length
    
            CoreUtilizationDisplay{
                width: root.elementWidth
                height: root.elementHeight
                core: index + 1
    
                value: sysinfo.coreUtilizationsInPercent[index]
    
                progressBarColor: "#3399FF" // blue
                minMaxTextColor: "blue"
            }
        }
    

    I thought I need to create the Objects dynamically. But since I know the count of cores at startup I can just use Repeater


Log in to reply