FunctionSorter QML Type | Qt 6.12
Description: Sorts data in a SortFilterProxyModel based on the evaluation of the designated 'compare' method.
Keywords: qmltype

- Qt 6.12
- QML Types
- FunctionSorter
- Qt 6.12.0 Reference Documentation

# FunctionSorter QML Type

Sorts data in a SortFilterProxyModel based on the evaluation of the designated 'compare' method. More...

Import Statement: | `import QtQml.Models`
Since: | Qt 6.10
Inherits: | Sorter
Status: | Deprecated since 6.12

This type is deprecated since QtQml.Models 6.12. We strongly advise against using it in new code.

- List of all members, including inherited members

## Detailed Description

FunctionSorter allows user to define the designated 'compare' method and it will be evaluated to sort the data. The method takes two arguments (lhs and rhs) of the specified parameter type and the data can be accessed as below for evaluation,

     SortFilterProxyModel {
         sourceModel: model
         sorters: [
             FunctionSorter {
                 id: functionSorter
                 component RoleData: QtObject {
                     property real age
                 }
                 function compare(lhsData: RoleData, rhsData: RoleData) : int {
                     return (lhsData.age < rhsData.age) ? -1 : ((lhsData === rhsData.age) ? 0 : 1)
                 }
             }
         ]
     }

Note: The `sort` method is deprecated. Rename it to `compare`.

Note: The user needs to explicitly invoke SortFilterProxyModel::invalidateSorter whenever any external qml property used within the designated 'compare' method changes. This behaviour is subject to change in the future, like implicit invalidation and thus the user doesn't need to explicitly invoke SortFilterProxyModel::invalidateSorter.