Performance tip QML other

From Qt Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.


Fixed length lists with Flickable+Column+Repeater

If you have a simple list with fixed length, you could try to optimize performance using Flickable+Column+Repeater instead of QML ListView. This way list creation would be slower, but list scrolling smoother.


Animate as small area of the screen as possible in transition animations

If you need to move 3 elements in a second try moving each at a time in 300ms. The system works so that it calculates the bounds of items that need repainting and paints everything inside those bounds. This can be really bad two little things are animating in opposite corners.


Avoid complex clipping

You should enable clipping only when you really need it. The default clip value is false.


Does it help performance if you strip off comments or white space from QML files?

Not really. The files are reprocessed into a binary in-memory representation at startup, so by runtime there should be no performance difference. You might be lucky and get 0.5% improvement, and then only on start-up (where QML parsing is done), nowhere else.


Avoid unnecessary conversion

QML performs a type conversion if the given value for a property does not match with the type specified for the property. This conversion consumes additional memory.


  • For example, =Image= and =BorderImage= have a source, which is of type =url=. Conversion is needed if image source's property is defined as =string=, it should rather be =property url=.
  • Wrong way:
property string messageAvatar: ""
  • Right way:
property url messageAvatar: ""

Beware of string operations

  • Multiple uses of the ' operator usually means multiple memory allocations
  • Use StringBuilder for more efficient strings.QStringBuilder uses expression templates and reimplements the operator so that when you use for string concatenation instead of ', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.
  • Define: QT_USE_FAST_CONCATENATION, QT_USE_FAST_OPERATOR_PLUS