Hi,

You may also try making backendCPP a singleton instead of inserting it in to 
the context. It is not out of the realm of possibilities that an object 
instance exposed to QML through a context property is nullptr when the QML 
object using it is constructed by the engine – thus yielding erratic results. 
The fact that you are seeing different results on different platforms points to 
a timing peculiarity on the lower end hardware.

Cheers,
James

From: Interest <interest-boun...@qt-project.org> on behalf of Alexander 
Dyagilev <alervd...@gmail.com>
Date: Thursday, July 29, 2021 at 4:17 PM
To: Nibedit Dey <nibedit....@gmail.com>
Cc: Jérôme Godbout <jgodb...@dimonoff.com>, Qt Project <Interest@qt-project.org>
Subject: Re: [Interest] Issues with QML binding
Sounds like a race condition bug affecting your method.

On Thu, Jul 29, 2021, 21:54 Nibedit Dey 
<nibedit....@gmail.com<mailto:nibedit....@gmail.com>> wrote:
Thank you for your inputs.
The values are fetched only once and assigned to the Text element.
This doesn't require any notification later as the data doesn't change in the 
app's lifetime.
Hence, I haven't used Q_PROPERTY and notification signals. However, the 
getStringData() has some logic inside it before returning the string.

This issue is sometimes seen in low-end embedded hardware and does not appear 
at all in desktop and high-end embedded devices. I know the issue can be fixed 
by using Q_PROPERTY and notification signals,
but I am trying to understand what might be going wrong in low-end embedded 
hardware. Debugging is not helping much here as it is not repeatedly 
reproducible.
It seems like there is some sync issue with Q_INVOKABLE method execution time 
and QML creation in some low-end hardware.

For example, if I want to show the version number of an application by invoking 
a C++ function like below:
text: "Version:" + backendCPP.getVersion()
Do you see any problem with the above line?

Thanks & Regards,
Nibedit

On Thu, Jul 29, 2021 at 11:18 PM Alexander Dyagilev 
<alervd...@gmail.com<mailto:alervd...@gmail.com>> wrote:

backendCPP.getStringData() is  a method. You can't bind it. You should use 
propery (Q_PROPERTY) and bind to it instead.
On 7/27/2021 6:50 PM, Nibedit Dey wrote:
Dear All,

I recently came across a strange issue related to QML binding.
The issue is not reproducible often which makes it difficult to find the root 
cause.
Sample QML code:
Case 1: text : "Retrieved details"+ backendCPP.getStringData()   //Sometimes, 
the complete string is empty
Case 2: property string someString : backendCPP.getStringData()
text: "Retrieved details:"+ someString // Displays Retrieved details: value 
remains empty
99% time, the value is fetched and displayed properly in Text element. Rarely, 
it remains empty.
Here backendCPP is a C++ instance exposed through context property and an 
invokable method is used to fetch data. Notify signal is not used in this case.
I believe during failure cases the data is not retrieved from backendCPP, when 
binding happened due to delay in the invokable method. Is my assumption correct?
Although we can handle the issue in multiple ways including using a NOTIFY 
signal or using Qt.binding, I am curious if anyone has observed this issue.
Please share your inputs.

Thanks & Regards,
Nibedit



_______________________________________________

Interest mailing list

Interest@qt-project.org<mailto:Interest@qt-project.org>

https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to