Skip to content

How to import a Rust method which returns data? #5333

Answered by hunger
Jackolix asked this question in Q&A
Discussion options

You must be logged in to vote

You will need to define a Customer struct in Slint:

struct Customer {
   name: string,
   age: int,
}

Then you can have a in property <[Customer]> model; in your main slint component with a list of those customers.

You use that model like this:

    for customer in root.model : Rectangle {
        height: 40px;
        width: parent.width;
        
        Button {
            x: 0;
            text: data.text;
            //color: white;
            width: parent.width;
        }
    }

Then you implement that model on the rust side (the Customer stuct is visible there!) and set it into the slint property.

The benefit of using a model is that you can add/remove/change elements in the model…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Jackolix
Comment options

Answer selected by Jackolix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants