Pages
API Documentation
On this page

KRoleNames QML Type

Maps role numbers and names of the attached model. This type was introduced in Qt 6.0. More...

  • Import Statement: import org.kde.kitemmodels
  • Since: Qt 6.0

Detailed Description

Attach KRoleNames to a model to map from roles to role names and vice-versa. It can be used to retrieve data from a model in an imperative fashion when a role enum is not available in QML (for example, when it is not exported via Q_ENUM) but role names are known; or to maintain consistency with view delegates (which use role names as properties).

Attached Method Documentation

[since 6.0] int role(string roleName)

Maps role name to role number.

Returns -1 if roleName is not found in the attached model's roleNames() hash map.

This method was introduced in Qt 6.0.

[since 6.0] string roleName(int role)

Maps role number to role name.

Returns an empty string if role is not found in the attached model's roleNames() hash map.

This method was introduced in Qt 6.0.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.