Results 1 to 2 of 2

Thread: QByteArray to int array

  1. #1
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QByteArray to int array

    Hello,
    I have a question about convertion QByteArray to int array.
    Here is example:
    Qt Code:
    1. QByteArray bin = file.readAll();
    2. //"bin" has a {10101010101}
    3. //for ex.: bin[0] returns 1, but it is not integer and I need to convert this to int array
    4. //I want to have result int: n {the same}
    To copy to clipboard, switch view to plain text mode 

  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: QByteArray to int array

    Your information and question are unclear.

    You have a QByteArray. It contains some number (n) of bytes: possibly characters, possibly not. You say the first byte is 1. Is that the value 0x01 or the character '1' (0x31)?

    You want to get these n bytes into an int[]. sizeof(int) is probably 4, are you expecting n/4 elements in your int array, or n?

Similar Threads

  1. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  2. Replies: 1
    Last Post: 22nd June 2011, 08:12
  3. Replies: 2
    Last Post: 12th November 2010, 14:42
  4. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24
  5. Replies: 9
    Last Post: 25th July 2009, 13:27

Tags for this Thread

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.