[Interest] QML engine, C++ model in secondary thread, signal lag, and infinite change loop

Stephen Bryant steve at bawue.de
Tue Mar 17 15:08:04 CET 2020

On 17/03/2020 11:30, Federico Ferri wrote:
> QML Engine <—> Proxy QObject <—> QObject model [worker QThread]
> Where is the flaw in my design?

"No one can serve two masters, for either he will hate the one and love
the other, or he will be devoted to the one and despise the other."
 -- Matthew 6:24

OK, so you weren't expecting the bible to provide answers to your
programming questions, but I felt it fits!

The flaw would be having multiple masters for the source of your value.

> How can this problem be solved in a way that every Qt engineer could say
> “yes, that’s how it should be done”? :-)

It's not only a Qt problem.  Those working with web applications are
confronted with this sooner, as the latencies are bigger.

That answer to to have a single source of truth.

In your design above, you have to choose one side, and decouple the
other.  You have effectively used bidirectional binding to give yourself
a race condition (or a feedback loop).

If you want the model to be the master, you could adjust your GUI design
into 2 elements: an interactive slider for the value the user wants, and
something non-interactive for the model's value.  You also have to
define how to handle when the user can't have what they wanted.

This behaviour is quite common in the real world.  When I set the
temperature on my oven, I get an indication that the current temperature
is something else.  Similarly with setting cruise control speed - the
speedo's needle may say something different.

Sometimes it's simpler to let the user be the master, and force your
model into submission.  At least, it's simpler for the GUI designer. :-)


More information about the Interest mailing list