Property override

This warning category is spelled [property-override] by qmllint.

Member does not override anything

What happened?

You marked a property as override without overriding anything. The base type of the current component has no property of the same name marked as virtual.

Why is that bad?

The QML engine throws a runtime error when it encounters such a property.

Example

 import QtQuick

 Item {
     component Base: Item { virtual property int myProperty; }
     Base {
         override property int myP: 42
     }
 }

To fix this warning, you can:

  • Remove the override-marker.
  • Double-check that the property name matches the name of a virtual or override property in the base type of the current component.
 import QtQuick

 Item {
     component Base: Item { virtual property int myProperty; }
     Base {
         property int myP: 42 // solution 1: remove override
         override property int myProperty: 42 // solution 2: fix spelling
     }
 }

Member shadows final member

What happened?

You shadowed a property which is marked as final.

Why is that bad?

Properties are marked as final to prevent overriding and shadowing. The QML engine throws a runtime error when it encounters the shadowing property.

Example

 import QtQuick

 Item {
     component Base: Item { final property int myFinal; }
     Base {
         property int myFinal: 42
     }
 }

To fix this warning, you can:

  • Rename the shadowing or shadowed property.
  • Replace the final marker with virtual or override and add missing override to the overriding property.
 import QtQuick

 Item {
     // solution 1: rename the property
     component Base: Item { final property int myFinal; }
     Base {
         property int myFinal2: 42
     }

     // solution 2: replace the final marker and add override
     component Base2: Item { virtual property int myFinal; }
     Base2 {
         override property int myFinal: 42
     }
 }

Member overrides final member

What happened?

You overrode a property which is marked as final.

Why is that bad?

Properties marked as final prevent overriding and shadowing. The QML engine throws a runtime error when it encounters the overriding property.

Example

 import QtQuick

 Item {
     component Base: Item { final property int myFinal; }
     Base {
         override property int myFinal: 42
     }
 }

To fix this warning, you can:

  • Rename the shadowing or shadowed property, and remove the override marker.
  • Replace the final marker with virtual from the overridden property.
 import QtQuick

 Item {
     // solution 1: remove override and rename
     component Base: Item { final property int myFinal; }
     Base {
         property int myFinal2: 42
     }

     // solution 2: replace final marker with virtual
     component Base2: Item { virtual property int myFinal; }
     Base2 {
         override property int myFinal: 42
     }
 }

Member shadows member

What happened?

You shadowed a virtual or override property without using final or override.

Why is that bad?

Properties that shadow virtual properties need a override or final marker. The QML engine throws a runtime warning when it encounters such a property.

Example

 import QtQuick

 Item {
     component Base: Item { virtual property int myProperty; }
     Base {
         property int myProperty: 42
     }
 }

To fix this warning, make the shadowing property override or final.

 import QtQuick

 Item {
     component Base: Item { virtual property int myProperty; }
     Base {
         override property int myProperty: 42 // could also be final
     }
 }

Member overrides a non-virtual member

What happened?

You overrode a property that was not marked as virtual or override.

Why is that bad?

Properties that can be overridden need to declare it via virtual or override. The QML engine throws a runtime error when it encounters the overridden property missing a virtual or override marker.

Example

 import QtQuick

 Item {
     component Base: Item { property int myProperty; }
     Base {
         override property int myProperty: 42
     }
 }

To fix this warning, rename the overriding property or mark the overridden property as virtual or override.

 import QtQuick

 Item {
     component Base: Item { virtual property int myProperty; }
     Base {
         override property int myProperty: 42
     }
 }

Property already exists in base type

What happened?

You shadowed a property without using as virtual, override, or final.

Why is that bad?

Properties that can be overridden need to declare it via virtual or override. The QML engine warns at runtime when it encounters the shadowing property.

Example

 import QtQuick

 Item {
     component Base: Item { property int myProperty; }
     Base {
         property int myProperty: 42
     }
 }

To fix this warning, rename the shadowing or shadowed property, or add the missing virtual, override, or final markers.

 import QtQuick

 Item {
     // solution 1: rename one of the properties
     component Base: Item { property int myProperty; }
     Base {
         property int myProperty2: 42
     }

     // solution 2: add missing markers
     component Base2: Item { virtual property int myProperty; }
     Base2 {
         final property int myProperty: 42 // could also be override
     }
 }