Print current timestamp in Milliseconds since epoch time in QML
-
Hi there,
I run an QtQuick Application together with some C++ Files, now i'd like to measure the time it takes between certain parts of the programm.
In C++ i can print the current timestamp, but is there a way to do it in QML? The console commands unfortunately don't cover this option.I'm sending data to a Slot of an QObject, which sends an signal to the QML File. I'm also open to other suggestions, which makesit possible to measure the time inbetween.
Kind regards
-
Hi, you can use Javascript Date object and getTime method
https://www.w3schools.com/jsref/jsref_gettime.asp -
Hello @LeLev and thank you for your answer!
In my QML file i use:
console.log(Date.now());
and in my .cpp file:
std::cout << QDateTime::currentMSecsSinceEpoch() << std::endl;
Unfortunately my QML file prints the time two times, because for some reason the signal of the qobject is received twice instead of once. I'm not the first one that has this problem, but to find the root of this problem is rather complecated (origin seems to be multithreading). If you know a easy workaround, so that the the
console.log
only gets printed every second time, please let me know.Kind regards
edit: getTime() doesn't work for some reason, i had to use Date.now()
-
@Philomath-Qt said in Print current timestamp in Milliseconds since epoch time in QML:
Unfortunately my QML file prints the time two times, because for some reason the signal of the qobject is received twice instead of once. I'm not the first one that has this problem, but to find the root of this problem is rather complecated (origin seems to be multithreading). If you know a easy workaround, so that the the console.log only gets printed every second time, please let me know.
I would rather try to fix the real issue, but if you really want to do that then go ahead..
@Philomath-Qt said in Print current timestamp in Milliseconds since epoch time in QML:
edit: getTime() doesn't work for some reason, i had to use Date.now()
the reason should be printed in the "application output" tab of you editor
this worksvar date = new Date() console.log(date.getTime())