P
P
Pavel K2015-08-31 02:57:48
Qt
Pavel K, 2015-08-31 02:57:48

How to force the qml component to update during long calculations?

Greetings!
I interact with qml from c++.
In general, in qml I want to change some property of the component before long calculations, for example, the color of the Rectangle.
So with setProperty("color", "red"); the color changes only after the assurance of long calculations.
If they are removed of course everything is ok.
I repeat, I change the property from the side of c ++ and not inside qml.
Those. The interface seems to hang for a while.
For example, code:

engine.rootObjects().at(0)->findChild<QObject*>("myRect")->setProperty("color", "red");

    qlonglong l = 1;
    while (l<1000000000000) {
        l+=1;
    }

How can you just update after setting the properties, but without transferring to another thread?
Something like the function waitForRedraw =) Tell me
how you can redraw

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2015-08-31
@PavelK

Pff. Found it myself =) QGuiApplication::processEvents();

A
Alexander Taratin, 2015-08-31
@Taraflex

Долгие вычисления всегда следует запускать в отдельном потоке.
В вашем случае, например через
doc.qt.io/qt-5.5/qtconcurrentrun.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question