derM
derM

Reputation: 13711

Changing default values for properties (e.g. asynchronous)

For many applications, especially on low-performance machines, it is beneficial to have built-in components, such as Loader and Image, setup to load their resources asynchronously. To do this, there are two obvious options:

  1. Set the required property of the built-in component, i.e. asynchronous: true
  2. Create a custom component AsyncXXX with basically this content:

AsyncXXX.qml:

XXX {
    asynchronous: true
}

where XXX is either Loader or Image.

I wonder why they are not set to asynchronous mode by default.

Most importantly, is there a way - an environment variable, a global setting - to change the default behaviour of built-in components to the asynchronous one, thus avoiding custom components?

Upvotes: 1

Views: 377

Answers (1)

dtech
dtech

Reputation: 49329

You could easily make ASLoader and ASImage QML types which are just Loader and Image with asynchronous: true and use those throughout your project. This will save you on having to modify it everywhere, and if you want to override that, you just go and change it in the prototype.

I wonder why they are not set to asynchronous mode by default.

Asynchronous is always more complicated and with more overhead, so it makes sense if it is not the default behavior. From the QML code I've seen, synchronous is used much more often than asynchronous, so it will make very little sense to make asynchronous default.

EDIT:

You could also achieve switching between synchronous and asynchronous behavior during the runtime if you bind the prototype to a project-wide property, for example a context property, or a property in main.qml.

Upvotes: 3

Related Questions