Originally Posted by
Damiann
anda_skoa, could you explain this to me more clear? I am not software engineer, and my C++ skill is quite low, especially Qt, which it totally new for me. The best help would be to show some code or make some changes in mine. Many thanks.
When you declare variables, in your case for example the array named "a", they are usually not initialized to some known value.
Putting the memcpy before the if fixes that for "a".
For the problem of prev_a, this needs to be in the class declaration, e.g. like this
{
private:
double prev_a[3];
};
class MyUDP : public QObject
{
private:
double prev_a[3];
};
To copy to clipboard, switch view to plain text mode
Again, remember that there the three values can be anything.
I would recommend using a vector instead, so that you can easily detect "first round of values"
{
private:
QVector<double> prev_a;
};
class MyUDP : public QObject
{
private:
QVector<double> prev_a;
};
To copy to clipboard, switch view to plain text mode
then you can check the size of prev_a to determine if this is the first time you receive data
bool gotUpdate = prev_a.isEmpty(); // no previous values, so we count this as an update
prev_a.resize(3);
memcpy(...);
gotUpdate = gotUpdate || (... value comparison...);
if (gotUpdate) {
// your code
}
bool gotUpdate = prev_a.isEmpty(); // no previous values, so we count this as an update
prev_a.resize(3);
memcpy(...);
gotUpdate = gotUpdate || (... value comparison...);
if (gotUpdate) {
// your code
}
To copy to clipboard, switch view to plain text mode
Cheers,
_
Bookmarks