-
I have written a Qt C++ code for my project. I am having trouble storing values in arrays. I have written a code for measuring the value from hardware. For storing first value I have used Array, that is working fine. For example when the program get started, I got initial value lets say 53.6854.
Now I want to take this value into another void for comparing with other values. So according to first value, I am going to check remaining values. I can't fix the constant value because Initial value will change every time.
I want to take that first value to void Motion::Synchronization(QString motiontype) else if(type == 2)
Then according to stored first value I will check remaining value. If that is not equal to that value I will create the other logic to reach that position. For that I need first value. I don't know how to change, or else any other ways to get the first value ? Assist me to solve this issue.
void check(float a) { std::cout << a << std::endl; } void Motion::Synchronization(QString type) { if(type == 1){ } else if(type == 2) { delay(20); } } void Motion::slow() { float n[ ] = {Thread::data}; check(n[0]); }
-
@Jerwinprabu I don't understand the problem: you get the first value from an array using 0 as index as you do already:
check(n[0]);
So, what is the problem?
-
@Jerwinprabu I moved your question to "C++ Gurus" forum as it isn't related to Qt but to C++.
-
@jsulm How can I take that stored value from Here
void Motion::slow() { float n[ ] = {Thread::data}; check(n[0]); }
to
else if(type == 2) { delay(20); }
-
@Jerwinprabu Not sure if I fully understand your problem, but why can't you create a local class variable for the value you need?
-
Hi,
To add to @Daniil-Chernyshev, why are you creating an array of one element to immediately take the first element ?
-
@Daniil-Chernyshev Because Each and every time value will update from hardware, so for every 5 milli second will get new value. In that same thread only I need first value and real time value.