Reputation: 667
Im working on a QML app that is consuming about 85% of the CPU when I emit a QString every 90ms to the QML display. We are currently using Qt 5.2. Im working on getting us up to Qt 5.9 because at this time we cannot go past 5.9.9 due to an older OS system.
So far the only thing I have been able to establish is that it appears because this QString from my model is embedded down in the hierarchy of QML there is a slowdown. Ive also removed the ListView out of the equation of updating items there by not emitting any changes on the backend C++ side. Conversely if I remove the 'emit my property()' call for the QString, CPU usage drops to 5%.
What I mean by that is that if I move the Text {} call to the top level (main.qml) and display it, all other things being equal, my CPU usage for the app goes from 85% down to 15%.
My app uses 4 floating windows, only 1 of which is currently implemented. My mode; property is located in the first QML 'Window' object. I found that if I changed that (Window) to a (Rectangle) my CPU usage drops to about 50%.
I also tried making the QString property defined at the top level (main.qml) and just use it in the lower 'Window' component without the model specifier, essentially using the top level one instead and found it equally slow (85%). I have a hard time believing that updating the screen for 1 QString causes such a CPU mess.
Unfortunately I cannot post the code because its proprietary but here is the basic outline of what it looks like (NOT REAL CODE).
I appreciate any pointers or knowledge anyone has about this situation. I have spent a bit of time searching for clues online with no real solutions found yet.
Thank you!
main.qml
ApplicationWindow
{
Rectangle
{
Row
{
FirstWindowButton {}
SecondWindowButton {}
ThirdWindowButton {}
ForthWindowButton {}
}
}
}
FirstWindowButton.qml:
Button
{
Loader
{
sourceComponent: Window
{
flags: Qt.Window
FirstWindow {}
}
}
}
FirstWindow.qml:
Rectangle
{
MyListView
{
}
}
MyListView.qml:
Rectangle
{
Text
{
text: theModel.string_value <----this is the slowdown line
}
ScrollView
{
ListView
{
}
}
}
Upvotes: 0
Views: 644
Reputation: 667
We finally figured out what was causing this issue after spending a while looking at performance issues that might cause issues with QML. Because we were using
the color
of a Rectangle
to colorized the background of ApplicationWindow
it was
having to redraw that entire Rectangle
every 90ms.
Instead use the color
property of ApplicationWindow
to colorize the background. Such a simple mistake and took many hours to figure it out.
Thank you for those who posted comments.
Upvotes: 1