Results 1 to 2 of 2

Thread: save variable size hex string into uchar array

  1. #1
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default save variable size hex string into uchar array

    Suppose that I have a number in hexadecimal notation
    with size 2n, like "aa00F234AA". I want to write it in
    an unsigned char array of size n ("aa" in the first
    byte, "00" in the second byte, etc) . In fact I want a
    function like this
    Qt Code:
    1. void f(unsigned char* dest, QString str);
    To copy to clipboard, switch view to plain text mode 
    How can I do this?
    Can I use QByteArray::fromHex()
    Thanks in advance.

  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: save variable size hex string into uchar array

    Yes, use QByteArray::fromHex() and then copy QByteArray::size() bytes out of the QByteArray::constData() buffer into your (preallocated) dest buffer using memcpy() or whatever.

    The question remains; do you really want to mix managed memory with the unmanaged C-style malloced blocks and pointers?

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

    amika (2nd November 2011)

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2018, 06:38
  2. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  3. how to concatenate a variable with a string
    By doforumda in forum Newbie
    Replies: 1
    Last Post: 25th August 2010, 08:34
  4. Get value for variable name defined as string
    By webquinty in forum General Programming
    Replies: 2
    Last Post: 18th November 2009, 10:30
  5. String Array
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2006, 07:53

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.