Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi programmers!
I have one issue while i am fetching data from DLL file.
C++
if (PCANReadS == PCAN_ERROR_OK)
{
    Dataid = QString::number(msg.ID, 16);
    nt temp =* (int*)msg.DATA;
    MsgType = msg.MSGTYPE;
    //MsgDLC = msg.LEN;
    MsgDLC = QString::number(msg.LEN, 10);
    Datain = QString::number(temp, 16);
    TStmpMilliCurrent = QString::number(timestamp.millis, 10);
    TStmpMicroCurrent = QString::number(timestamp.micros, 10);
}


What i want to do is getting the difference between current time stamp and previous.
When i subtract it gives me error because both are in Qstring.
How i can get this difference between two time stamps?
Posted
Updated 11-Nov-15 4:29am
v3
Comments
Jochen Arndt 11-Nov-15 9:54am    
Why you are converting all numbers to QString?
Just subtract the previous numbers (which are not present in your example) from the current ones.
Ramiien 11-Nov-15 9:58am    
int TStmpMilliCurrentInt = atoi(TStmpMilliCurrent);

getting msg cannot convert Qstring to const Char
Jochen Arndt 11-Nov-15 10:06am    
Why do you convert a number to a QString and try to convert it back to a number later?

A QString contains Unicode strings (UTF-16). So you must use the wide character functions (e.g. _wtoi with Windows) or the QString member function toInt().
Ramiien 11-Nov-15 10:18am    
Actually i am getting time in milli seconds from CAN and trying to get the time difference between two frames
Jochen Arndt 11-Nov-15 10:22am    
Then store the time in a variable (as number) and when receiving the next frame calculate the difference and write the new time afterwards into the variable.
[EDIT]
The variable must hold its value. So it must be a global one or a C++ class member when the class is not destroyed.

1 solution

An incomplete example on how to store a timestamp based on the available code:

C++
int prevTime = 0;

void someFunction()
{
    if (PCANReadS == PCAN_ERROR_OK)
    {
        int diffTime = 0;
        // If not first frame
        if (prevTime)
            difftime = timestamp.millis - prevTime;
        prevTime = timestamp.millis;
    }
}

It would be better to use the same type as timestamp for the global variable. But I did not know the type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900