Results 1 to 3 of 3

Thread: QByteArray can't read all the data provided

  1. #1
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation QByteArray can't read all the data provided

    I am inserting a HEX code in the QByteArray variable,
    That hex isn't for a normal txt file, it's for an EXECUTABLE one, so it contains binary information

    Qt Code:
    1. QByteArray hex = "fff0000b800000000000000400"; // Very long hex string
    2. hex = QByteArray::fromHex(hex);
    3. hex = hex.data();
    4. int hexx = hex.size(); // outputs "3" while the real size is about 486400 byte
    To copy to clipboard, switch view to plain text mode 

    also when I output the result it only shows "MZ" and these are the first two characters of the .exe when opend with notpad.
    and th rest characters are ASCII and unknown ones.

    I need your help to complete this task.
    Reason: I want to inject a binary data converted from hex into another process using QProcess.
    Thanx.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,532
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray can't read all the data provided

    First remember that QByteArray::data returns char pointer i.e. the pointer to NULL terminated string and so it is used.
    Second QByteArray::data says The pointer remains valid as long as the byte array isn't reallocated or destroyed. I think that line 3 is pointless.

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

    Vladimir_ (15th September 2014)

  4. #3
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QByteArray can't read all the data provided

    Okay, I deleted the line 3.

    I used QFile to write the data directly to an executable file.

    Successfully I executed the program. I gave you a thanx for that.

    But the main issue is using QProcess to execute this binary without writing it in external file.

    I will make another thread for that, and keep this one for the people wwho had the same issue.

    Thank you.
    Last edited by Vladimir_; 15th September 2014 at 18:57.

Similar Threads

  1. Replies: 2
    Last Post: 23rd June 2012, 03:21
  2. problem with QByteArray data !
    By Con Nít in forum Qt Programming
    Replies: 6
    Last Post: 24th January 2011, 11:50
  3. inver data from QByteArray
    By aj2903 in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2010, 07:56
  4. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  5. How to read a Number from the QByteArray
    By antonio.r.tome in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2006, 15:24

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.