Results 1 to 3 of 3

Thread: hex from Qlineedit and checksum

  1. #1
    Join Date
    Jul 2015
    Posts
    18
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default hex from Qlineedit and checksum

    I have a Qlineedit that I want the user to input hex freely without restriction. I've tried to use setInputMask but you have to know the size before hand in order to set it up. So I was wondering if there is a way to do what I want.

    Another thing is after the user inputs hex values, how can I grab them and put them into my char array to do checksum and send it to the serial port?

    So basically an example of what I want is this:

    char array with 0x01, 0x10, 0x20, 0x00, 0x01, 0x00 in the front, then the user inputs some random hex like 1234 in the Qlineedit. And then when a button is pushed, the hex in the Qlineedit will be added to the char array, and then something will calculate the checksum and add it to the char array also. Then I can also add the end byte at the end of the array. The final char array should have these:
    Qt Code:
    1. {0x01, 0x10, 0x20, 0x00, 0x01, 0x00, 0x12, 0x34, 0x78, 0x04}
    To copy to clipboard, switch view to plain text mode 
    (0x12 and 0x34 from Qlineedit, 0x78 is the checksum and 0x04 is the end byte)

    Thank you!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: hex from Qlineedit and checksum

    You can limit the user input with a QValidator sub-class. You can remove any character that is not valid hex in the validate function, and also flag Intermediate on odd-numbers of chars. The packet assembly could happen in the slot attached to the button if the input is valid.

    Alternatively, a QLineEdit subclass could intercept and swallow keypresses that were not valid.

  3. #3
    Join Date
    Jul 2015
    Posts
    18
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: hex from Qlineedit and checksum

    Thank you for the reply, but can you please elaborate and give me an example of how the codes should look like? I'm still new to Qt and therefore am not familiar with all the functions that are in those classes.

Similar Threads

  1. Qt CRC64 Checksum
    By alrawab in forum Newbie
    Replies: 1
    Last Post: 20th January 2013, 01:08
  2. crc checksum
    By kodiak in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 09:27
  3. calculating checksum in serialcommunication
    By jjbabu in forum Qt Programming
    Replies: 5
    Last Post: 12th October 2007, 12:43
  4. checksum routines?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2007, 00:26

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.