Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Print current timestamp in Milliseconds since epoch time in QML

Print current timestamp in Milliseconds since epoch time in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 8.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Philomath-Qt
    wrote on 30 Jan 2021, 15:08 last edited by Philomath-Qt
    #1

    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

    O 1 Reply Last reply 30 Jan 2021, 15:39
    0
    • P Philomath-Qt
      30 Jan 2021, 15:08

      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

      O Offline
      O Offline
      ODБOï
      wrote on 30 Jan 2021, 15:39 last edited by
      #2

      @Philomath-Qt

      Hi, you can use Javascript Date object and getTime method
      https://www.w3schools.com/jsref/jsref_gettime.asp

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Philomath-Qt
        wrote on 30 Jan 2021, 17:21 last edited by Philomath-Qt
        #3

        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()

        O 1 Reply Last reply 30 Jan 2021, 19:10
        0
        • P Philomath-Qt
          30 Jan 2021, 17:21

          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()

          O Offline
          O Offline
          ODБOï
          wrote on 30 Jan 2021, 19:10 last edited by
          #4

          @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 works

          var date = new Date()
          console.log(date.getTime())
          
          1 Reply Last reply
          0

          3/4

          30 Jan 2021, 17:21

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved