Results 1 to 2 of 2

Thread: Get QByteArray from QString

  1. #1
    Join Date
    Nov 2012
    Location
    Poland/UK
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Get QByteArray from QString

    Hi all

    Look at this code

    Qt Code:
    1. QString cmd = "some strings here";
    2. long buffer = 2048;
    3. QByteArray array;
    To copy to clipboard, switch view to plain text mode 
    I want get first 2048 byte from QString cmd to array in Utf8. Dont know how. Any suggestions?
    And when i got first 2048 byte, how to take next bytes.
    In QFile is simple

    Qt Code:
    1. QFile file("file");
    2. QByteArray array = file.read(buffer);
    3. file.seek(buffer);
    4. array = file.read(buffer);
    To copy to clipboard, switch view to plain text mode 

    Ty for any help.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Get QByteArray from QString

    Quote Originally Posted by Coder5546 View Post
    I want get first 2048 byte from QString cmd to array in Utf8. Dont know how. Any suggestions?
    Qt Code:
    1. QByteArray array = cmd.toUtf8();
    2.  
    3. QByteArray first2048Bytes = array.mid( 0, 2048 );
    4. QByteArray second2048Bytes = array.mid( 2048, 2048 );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Coder5546 View Post
    And when i got first 2048 byte, how to take next bytes.
    Qt Code:
    1. QByteArray second2048Bytes = array.mid( 2048, 2048 );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Coder5546 View Post
    In QFile is simple
    You can alternatively put array into a QBuffer and use that like the file.

    Cheers,
    _

Similar Threads

  1. QByteArray to Qstring
    By bmps in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2011, 21:02
  2. Problem with QString and QByteArray
    By ts66 in forum Newbie
    Replies: 2
    Last Post: 10th May 2011, 22:30
  3. QByteArray to QString
    By hvitual in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2009, 11:43
  4. QByteArray to QString
    By babu198649 in forum Newbie
    Replies: 7
    Last Post: 6th December 2007, 14:08
  5. How to get QByteArray from QString in Qt3
    By joseph in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2007, 10:23

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.