Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt equivalent of timeGetTime()



  • Is there in the QT libraries an equivalent of the timeGetTime() function of the Windows.h header? I wish my code was as platform-independent as possible. I know the <chrono> header exists, but I would like something that returns the value in DWORD

    QWORD lastpos;
    DWORD lasttime;
    ...
    float AudioThread::br()
    {
        QTime tmp(0,0,0);
        DWORD time = tmp.msecsSinceStartOfDay();
        QWORD pos = BASS_StreamGetFilePosition(chan, BASS_FILEPOS_CURRENT);
            if (pos != lastpos) {
              lasttime = time;
              lastpos = pos;
            }
        }
        qDebug() << tmp.msecsSinceStartOfDay();
        return 8.0 * (pos - lastpos) / (time - lasttime);
    }
    

    Calling this function into a QTimer, tmp.msecsSinceStartOfDay() always returns 0

    Can you help me?

    Thanks in advance


  • Lifetime Qt Champion

    Hi,

    You are asking for contradictory things. You want a cross-platform solution yet you want the return type to be system specific. So either use the API provided by that platform or do the conversion to DWORD in your code for that platform.


  • Moderators

    For measuring how much time passed use QElapsedTimer. As SGaist said DWORD is not platform-independent and it can be a little small for holding milliseconds so if you don't want a dedicated standard chrono types stick to either Qt's types like qint64 or standard ones like int64_t.


Log in to reply