In order to expand the nodes of a TreeView to show the currently selected item (set by a shared selection model) I need to call TreeView.expand(QModelIndex) recursively.

```
    expand(index)
    expand(index.parent)
    expand(index.parent.parent)
    ...

```

this could be done by a function like this:

```
 function autoExpand(index ) {
    print(index)
    var oneUp = index

    do {

        print(oneUp)
        oneUp = index.parent
        expand(oneUp)
        print("do")
        print(oneUp)
    } while (oneUp)

}

```

however I don't know how to check for the root node. I tried

```
 while (oneUp)  -> always true
 while (oneUp.isValid) -> undefined ie always false
 while (oneUp.isValid()) -> property isValid cannot be called as a function

```

, in c++ it would be:

```
do {
   //....
} while (oneUp.isValid());

```

but I cannot find an equivalent function in QML (and don't know where to look for the code ...)

As a workaround I check it in c++ in an object that is already exported but well, it doesn't look proper:

```
public slots:
   bool indexIsValid(const QModelIndex &index) const {return index.isValid();}

```