Well, the value of QLcdNumber is set using the display() property. For the first time dealing with QLcdNumber shows a strange behavior.
Consider this example:
{
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 number and qlcd are set to -3.6xx
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 number and qlcd are set to -3.6xx
To copy to clipboard, switch view to plain text mode
it's strange!
Bookmarks