Results 1 to 5 of 5

Thread: Bytes help again D:

  1. #1
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    11

    Default Bytes help again D:

    Hi, i'm new in qt and i don't know how to send bytes D:

    I want to follow this protocol:
    C: 04
    CC: 04
    Name: THREAD_REPLY
    Format (Sent): thread_id (int), message [short, string]

    I tried it, but doesnt worked:
    Qt Code:
    1. QByteArray reply;
    2. reply[0] = 0x00;
    3. reply[1] = 0x00;
    4. reply[2] = 0x00;
    5. reply[3] = 0x2f;
    6. reply[4] = 0x04;
    7. reply[5] = 0x04;
    8. reply[6] = 0x00;
    9. reply[7] = 572436;
    10. reply[8] = 0x00;
    11. reply[9] = 0x00;
    12. reply[10] = 0x00;
    13. reply[11] = ui->lineEdit->text().toUtf8();
    14.  
    15. sendPacket(reply);
    To copy to clipboard, switch view to plain text mode 


    Thanks!
    Attached Images Attached Images

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

    Default Re: Bytes help again D:

    What about it doesn't work? We are not mind readers.

    Some general observations:
    • If the packet is supposed to be a four byte int (assumed) followed by a two byte short indicating the length of the following string then the list of bytes you have there is too long.
    • Multi byte integers are sensitive to byte order issues. Make sure sender and receiver agree.
    • Line 9 makes no sense. You cannot put that number in a single byte.
    • Line 11 tries to put an entire string in a single byte. Did you perhaps intend to append the string?

  3. The following user says thank you to ChrisW67 for this useful post:

    Niunzin (6th January 2014)

  4. #3
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    11

    Default Re: Bytes help again D:

    I need to convert an String to Hex (like J -> 6a) and add it to the byte array D:

  5. #4
    Join Date
    Jun 2006
    Posts
    81
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Bytes help again D:

    Have a look at QByteArray::toHex().

  6. The following user says thank you to zaphod.b for this useful post:

    Niunzin (6th January 2014)

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

    Default Re: Bytes help again D:

    No, you want to append the bytes of the string to the bytes already in the array. You are part way there with QString::toUtf8() (which gives you an eight-bit encoded string in a byte array) but you want to use QByteArray::append() or QByteArray::operator+().

  8. The following user says thank you to ChrisW67 for this useful post:

    Niunzin (6th January 2014)

Similar Threads

  1. Help to send bytes
    By Niunzin in forum Qt Programming
    Replies: 5
    Last Post: 6th January 2014, 22:30
  2. Replies: 4
    Last Post: 23rd October 2012, 08:40
  3. QString in bytes
    By estanisgeyer in forum Newbie
    Replies: 1
    Last Post: 23rd October 2010, 16:04
  4. How to get an array of bytes from a DLL?
    By srohit24 in forum Qt Programming
    Replies: 5
    Last Post: 22nd April 2009, 16:11
  5. How many bytes did i send?
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2008, 10:12

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
  •  
Qt is a trademark of The Qt Company.