Results 1 to 2 of 2

Thread: QLCDNumber strange behavior!

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QLCDNumber strange behavior!

    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:
    Qt Code:
    1. void MainWindow::dataFromUdp(QByteArray pack)
    2. {
    3. if(pack.at(0) == '!')
    4. {
    5. unsigned long x;
    6.  
    7. x = (unsigned char)pack[pack.length() -1] +
    8. (unsigned char)pack[pack.length() -2] * 256 +
    9. (unsigned char)pack[pack.length() -3] * 256 * 256 +
    10. (unsigned char)pack[pack.length() -4] * 256 * 256 * 256;
    11.  
    12. //extract packet
    13.  
    14. if(x == crcCalculate(0, pack.length() - 4, pack))
    15. {
    16. //CRC is correct
    17.  
    18. if(pack[1] == 0x0d)
    19. {
    20. number = 0; // class member variable
    21. char value[6];
    22. sprintf(value,"%c%c%c%c%c", (char)pack[2],(char)pack[3],(char)pack[4],
    23. (char)pack[5],(char)pack[6]);
    24.  
    25. //Now value = 00125
    26.  
    27. number = atoi(value)/1000.0;
    28.  
    29. //Now value is 0.125
    30.  
    31. ui->lcd_range->display(number);
    32.  
    33. qDebug() << number;
    34.  
    35. //Here number and qlcd are set to -3.6xx
    To copy to clipboard, switch view to plain text mode 

    it's strange!

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QLCDNumber strange behavior!

    Quote Originally Posted by saman_artorious View Post
    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:
    Qt Code:
    1. void MainWindow::dataFromUdp(QByteArray pack)
    2. {
    3. if(pack.at(0) == '!')
    4. {
    5. unsigned long x;
    6.  
    7. x = (unsigned char)pack[pack.length() -1] +
    8. (unsigned char)pack[pack.length() -2] * 256 +
    9. (unsigned char)pack[pack.length() -3] * 256 * 256 +
    10. (unsigned char)pack[pack.length() -4] * 256 * 256 * 256;
    11.  
    12. //extract packet
    13.  
    14. if(x == crcCalculate(0, pack.length() - 4, pack))
    15. {
    16. //CRC is correct
    17.  
    18. if(pack[1] == 0x0d)
    19. {
    20. number = 0; // class member variable
    21. char value[6];
    22. sprintf(value,"%c%c%c%c%c", (char)pack[2],(char)pack[3],(char)pack[4],
    23. (char)pack[5],(char)pack[6]);
    24.  
    25. //Now value = 00125
    26.  
    27. number = atoi(value)/1000.0;
    28.  
    29. //Now value is 0.125
    30.  
    31. ui->lcd_range->display(number);
    32.  
    33. qDebug() << number;
    34.  
    35. //Here number and qlcd are set to -3.6xx
    To copy to clipboard, switch view to plain text mode 

    it's strange!
    Found the bug, the server was unwillingly sending a second packet right after the first one. So, the second one overwrote the first without eye noticing it.

    Cheers,

Similar Threads

  1. setCellWidget - strange behavior
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 28th April 2011, 08:26
  2. QSqlDatabase strange behavior
    By macav in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2011, 15:21
  3. strange behavior of paintEvent
    By hashb in forum Qt Programming
    Replies: 3
    Last Post: 30th August 2010, 07:48
  4. QComboBox strange behavior
    By Antebios in forum Newbie
    Replies: 2
    Last Post: 31st March 2009, 23:50
  5. Strange behavior of QSyntaxHighlighter in Qt3
    By lorebett in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2009, 14:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.