Results 1 to 4 of 4

Thread: File Editing (Binary/Hex) with Qt 4.6.2

  1. #1
    Join Date
    Oct 2009
    Location
    Edge of Nowhere
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default File Editing (Binary/Hex) with Qt 4.6.2

    What I'm basically trying to do is create a save game editor for Dynasty Warriors 6 using Qt. The save file itself is about 700kb large (might be a bit more, don't have a sample w/ me). I know the exact offsets of the different values I'm looking for (say experience), and I know how big they are (32-bit unsigned integer in big endian format). However, every time I try to extract these values and place them into a SpinBox control, I get nothing.

    Basically what I do is this:

    1) Establish QFile object as normal (use a QString with the QFileDialog::getOpenFileName() function).

    2) Create a temporary QByteArray to store the values (the array is flushed for each value).

    3) Make sure everything is ok with the QFile object, checking the isOpen() and isReadable() properties and so on.

    4) Seek to the offset (ie 0x1240).

    5) Use the Read() function to read 4 bytes into the temporary array.

    6) Set the SpinBox's current value to the array's toUInt() function. (Considering there's no toQInt32() function, pity.)

    7) Display a message confirming completion of the process.

    It seems to get through all the steps just fine, and even shows the confirmation message, but the SpinBox doesn't go from 0 to 99,999 like it would from my save game, because the value at offset 0x1240 is 99,999; I can crack it open in my hex editor and stare it right in the face.

    I've also tried using the readAll() function to read the file into a QByteArray serving as a buffer (inefficient and expensive, I know), but even that doesn't work.

    I've looked into the temporary array during debugging, and it shows the proper value (0x0001869F), but it doesn't show on the SpinBox, it doesn't show on a TextBox, or a QMessageBox.

    In short, what in Petraeus' name is going on here? I swear, Qt has it out for me...
    We do what we must. Because we can.

  2. #2
    Join Date
    Oct 2009
    Location
    Edge of Nowhere
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: File Editing (Binary/Hex) with Qt 4.6.2

    Quick addendum to my above post. The save file isn't 700+ kb, its only 206kb (208kb on disk). I've tried using a QDataStream, as well, with the same results as if I were using the above method. The only thing I haven't tried is using the i/fstreams in <iostream>. I'll test that and post my results, if any...
    We do what we must. Because we can.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: File Editing (Binary/Hex) with Qt 4.6.2

    If you call toUint on the text "1234", it will return the number 1234.

    Your 32-bit unsigned number stored in a QByteArray clearly isn't text, so toUint clearly isn't going to do the job.

    The question is, why not just do it yourself? For example, uint32 = array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3] for example?

  4. #4
    Join Date
    Oct 2009
    Location
    Edge of Nowhere
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: File Editing (Binary/Hex) with Qt 4.6.2

    Didn't think about that...I'll give it a shot.

    I found a weird solution, but it requires going around the QFile class with the Standard Library equivalent, but its a bit...clunky. So, I'll try your idea.
    We do what we must. Because we can.

Similar Threads

  1. Editing text file via console app
    By cejohnsonsr in forum Newbie
    Replies: 1
    Last Post: 30th August 2010, 21:39
  2. Editing the file using the seek operations
    By grsandeep85 in forum Qt Programming
    Replies: 4
    Last Post: 24th March 2010, 04:30
  3. editing *.pro file in Visual Studio
    By estel in forum Newbie
    Replies: 2
    Last Post: 8th February 2010, 06:31
  4. Editing a file in Qt4
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2009, 09:33
  5. How to Print a doc file (or binary file) to printer
    By rmagro in forum Qt Programming
    Replies: 15
    Last Post: 5th September 2008, 15:46

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.