0

I have this function, written in C++ using QTcreator, to return the current time of the system being used.

void cLogDataBase::writetime()
{
    QString Str;
    Str = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
    writestr(Str);
}

My issue is that I return my data to a CSV file and then again as a graph so I do require the axis / values to be consistent. In this case Time.

enter image description here

This image better illustrates my issues, as with the second value set ( or values between 3 and 3.9 seconds) it goes 3.1,3.2..3.4, completely skipping 3.2 seconds and thus causing the output to be skewed

Is it possible to manipulate my Str variable to do this or would something else in my code control this ? if its the latter then I can look through and post another question. I just want to see if its possible to fix within this function.

Thanks in Advance.

Adam Gong
  • 41
  • 5
  • 1
    Your code isn't running exactly once every 10 seconds, you could try and make it run more accurately but you're probably better off just recording the time more accurately and deal with the imperfect intervals when processing your results – Alan Birtles Aug 28 '23 at 05:24
  • @AlanBirtles Would having its own timer not based on the current Date and time be a better option ? – Adam Gong Aug 28 '23 at 05:36
  • Yes, in general for measuring elapsed time you should use a monotonic clock like `QElapsedTimer` – Alan Birtles Aug 28 '23 at 05:40
  • why do you think the issue is with `QTDateTime` ? How do you call the function? What is `writestr` ? Please post a [mcve] – 463035818_is_not_an_ai Aug 28 '23 at 05:53
  • 1
    If you call your log with a `QTimer`, it is probably related to [this question](https://stackoverflow.com/questions/22560908/strange-accuracy-of-qtimer-with-windows-8?rq=3). But no matter what you use for sampling, if it is software, you cannot expect it to be 100% accurate. Better change your graph into an X-Y variant that can deal with variable time steps – Homer512 Aug 28 '23 at 06:09

0 Answers0