141 views
in GUI Development by
Hi team,

In Init() method of a class, while trying to access the objects/properties in that class, it is null, I need to pass a property in this class to a method only once during init, this class will be triggered by external screen where this class is given as a object and this property value is configured in that object over there.

I couldn't get configured value of that property, in init() of the class it is having null only during init, how to achieve this ?

Thanks in advance,
Meenakshi Sundaram S R.

1 Answer

0 votes
by

Hello Meenakshi Sundaram S R.,

I couldn't get configured value of that property, in init() of the class it is having null only during init, how to achieve this ?

I have no idea, what you mean. Please provide an example.

Best regards

Paul Banach

by

Hi Paul.

I will give a sample project below.

As you can see in the above image, I have given value 56 to the object in the screen. 

I am trying to call the method in the class from screen1.

so, test_cls will have these properties and method inside, I have given 56 to prprty.

after update is called from screen, Init of test_cls will be triggered priniting the prprty value.

After init called update method will be invoked, printing the same prprty value.

As reference to the above debug window, you can see that, prprty value is 0 in Init method and 56 in update method.

 

I need to get 56 during Init itself, to further process that value one time only before update. How to proceed with this to achieve the desired outcome.

 

Thank you,

Meenakshi Sundaram S R.

by

Hello Meenakshi Sundaram S R.,

this behavior is correct. The modification of properties of an object (in your example the property prprty of the object test_cls) is performed after the object has finished its own initialized.

This initialization propagates through the ancestor classes of the object, starting with the oldest class. At the end of each class-initialization the corresponding method Init() is invoked.

Therefore the Init() methods in all classes defining the object ancestry are invoked before the object can be accessed and its data members (e.g properties) can be modified from the outside of the object.

Any other behavior would have unpredictable side effects of not finally initialized data members.

Best regards

Paul Banach

by
Hi Paul,

As reference to the sample project given above, I need to take the value (56) which I have given in screen and process for one time, As I wanted to do that for one time. I tried to post signal the slot from the init of that class, so that when that slot is post signaled from init It will trigger one time, also the property will be initialized with the expected value.

But the issue is I am calling the update() method of this class from the screen, that update() should only be executed once that post signaled execution is completed. As it is getting signaled from init and update is called from the screen, I couldn't determine the sequence.

1) post signaled slot is getting executed first then update.

2) update is getting executed first then post signaled slot from init

 

I want the 1st sequence to occur, not the second one, if second sequence occurs it will crash the system. It is not possible using post signaling from init, is there any other reliable and efficient way to do this.

 

Thank you,

Meenakshi Sundaram S R.
by

Hello Meenakshi Sundaram S R.,

I want the 1st sequence to occur, not the second one

Using signal instead of postsignal could eventually help you.

Best regards

Paul Banach

by
Hi Paul,

I have already tried signaling the slot from init, but I couldn't get the value given from the object (couldn't get 56 in reference to the sample project), it is only having the initial value assigned in the class (0 in reference to the sample project), while using post signal only I am able to get 56 in that slot.

But I don't have an assurance that post signal slot from init will trigger before the update method, I need to achieve that sequence.

 

Thank you,

Meenakshi Sundaram S R.
by
Hello Meenakshi Sundaram S R.,

as explained in my answer, this is not possible. The object is first initialized, then the new property value 56 can be assigned to the object. The Init methods associated to the object are invoked during object initialization. Thus before the value 56 is assigned.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...