Furkanzmc / QML-Coding-Guide

A collection of good practices when writing QML code - https://doc.qt.io/qt/qtqml-index.html
The Unlicense
538 stars 80 forks source link

Question about having "root" as id for top-most component #6

Closed daravi closed 4 years ago

daravi commented 4 years ago

I'm wondering what is the reasoning behind this guideline:

Make sure that the top most component in the file always has root as its id.

Why not have each file have an id that describes them?

// SomeComponent.qml
Item
{
  id: someComponent
}

As opposed to the generic root?

OlivierLDff commented 4 years ago

I like when i read in a qml file root.someproperty. I always know it is some kind of property exposed to the user. It also help to be consistent across multiple file. You always know that root is the top hierarchy item. Where as someComponent isn't that obvious.

daravi commented 4 years ago

Ok thanks!

My worry was that if I forget to call it root then the parent component will be referenced instead (because that one is also called root and is now visible). But I guess if I am consistent then that shouldn’t happen and there is value in immediately knowing that root means the top level item.