什么是正确的转换unsigned int方式double?我需要这是用于QCPCustomPlot数据设置,因为它QVector<double> 恰好作为创建图形的参数.
编辑:傻我."内存泄漏"错误问题是由于我QVector<double> x(time), y(ipv4int)错误地初始化而引起的.改变后的time值相同ipv4int(数据occurence频率)和x与y正确的匹配.
完成time变量,现在是有关转换的实际问题.如何将其转换为double包含值的格式,1855919686而不是格式为1.85592e+09?
QCustomPlot需要double但似乎QVector<double>不能像1.85592e + 09那样接受价值
更新的代码:
QVector<double> x(i), y(totalIP); //i=236052
for(int o = 0; o <= i; o++){
double dSec = arrayIPxTime[o][0] - startSecond; //arrayIPTime[o][0] holds time in second
double dMin = dSec/60;
double ipv4addr = arrayIPxTime[o][1]; //arrayIPTime[o][0] holds ipaddr in integer format
x[o] = dMin;
//y[o] = ipv4addr; this is the line that causes crash.
qDebug()<<"Count "<<o<<" time "<< x[o] <<" ipv4 "<<ipv4addr<<" arrayIPxTime[o][1] "<<arrayIPxTime[o][1];
}
Run Code Online (Sandbox Code Playgroud)
当前输出:
Count 236048 time 62.3167 ipv4 1.85592e+09 arrayIPxTime[o][1] 1855919686
Count 236049 time 62.3167 ipv4 1.85592e+09 arrayIPxTime[o][1] 1855919686
Count 236050 time 62.3167 ipv4 1.85592e+09 arrayIPxTime[o][1] 1855919686
Count 236051 time 62.3167 ipv4 1.85592e+09 arrayIPxTime[o][1] 1855919686
Run Code Online (Sandbox Code Playgroud)
请放心,在转换unsigned int到double没有不导致内存泄漏.
写作double b = a;绰绰有余,或者只是传递a给需要double作为参数的函数.
请注意,对于IEEE754双精度浮点类型,转换精确到unsigned int最高为53的2次幂.