好吧,QLcdNumber 的值是使用 display() 属性设置的。第一次处理 QLcdNumber 显示出奇怪的行为。考虑这个例子:
void MainWindow::dataFromUdp(QByteArray pack)
{
if(pack.at(0) == '!')
{
unsigned long x;
x = (unsigned char)pack[pack.length() -1] +
(unsigned char)pack[pack.length() -2] * 256 +
(unsigned char)pack[pack.length() -3] * 256 * 256 +
(unsigned char)pack[pack.length() -4] * 256 * 256 * 256;
//extract packet
if(x == crcCalculate(0, pack.length() - 4, pack))
{
//CRC is correct
if(pack[1] == 0x0d)
{
number = 0; // class member variable
char value[6];
sprintf(value,"%c%c%c%c%c", (char)pack[2],(char)pack[3],(char)pack[4],
(char)pack[5],(char)pack[6]);
//Now value = 00125
number = atoi(value)/1000.0;
//Now value is 0.125
ui->lcd_range->display(number);
qDebug() << number;
//Here qDebug() and qlcd both show -3.6xx
你有什么主意吗?