Hello.
I'm porting some code from C# to Qt4 and I met some problems.
The program opens a binary file and retrieves some data from it.

This is code in C#:

Qt Code:
  1. string scriptName = args[0];
  2. Encoding jis = Encoding.GetEncoding(932);
  3. using(BinaryReader script = new BinaryReader(scriptFile.OpenRead(), jis))
  4. {
  5. script.BaseStream.Seek(0x020, SeekOrigin.Begin);
  6. uint opcode = script.ReadUInt32();
  7. uint codeSize = script.ReadUInt32();
  8.  
  9. script.BaseStream.Seek(0, SeekOrigin.Begin);
  10. byte[] scriptBuffer = script.ReadBytes((int)codeSize);
  11.  
  12. for(int dwptr = 0; dwptr < codeSize; dwptr += 4)
  13. {
  14. uint currentDw = scriptBuffer[dwptr];
  15. if(currentDw != 0x03 && currentDw != 0x07F)
  16. continue;
  17.  
  18. dwptr += 4;
  19. currentDw = ToUInt32(scriptBuffer, dwptr);
  20. }
  21. }
To copy to clipboard, switch view to plain text mode 

and reimplemented ToUInt32 (in C#):
Qt Code:
  1. static uint ToUInt32(byte[] array, int beginOfs)
  2. {
  3. return(uint)((array[beginOfs+3] << 24) | (array[beginOfs+2] << 16) | (array[beginOfs+1] << 8) | (array[beginOfs]));
  4. }
To copy to clipboard, switch view to plain text mode 

I ported this code to:

Qt Code:
  1. QFile cScript(fPath+"/"+fName);
  2. cScript.open(QIODevice::ReadOnly);
  3.  
  4. QDataStream cData(&cScript);
  5. cData.setByteOrder(QDataStream::LittleEndian);
  6.  
  7. cScript.seek(0x020);
  8.  
  9. quint32 opcode;
  10. quint32 codeSize;
  11.  
  12. cData >> opcode;
  13. cData >> codeSize;
  14.  
  15. cScript.seek(0);
  16. QByteArray fragment = cScript.read(codeSize);
  17.  
  18. for(quint32 dwptr = 0; dwptr < codeSize; dwptr += 4)
  19. {
  20. quint32 curr = fragment[dwptr];
  21. if(curr != 0x03 && curr != 0x07F)
  22. continue;
  23.  
  24. dwptr +=4;
  25. curr = toUint32(fragment, dwptr);
  26. }
To copy to clipboard, switch view to plain text mode 

and toUint32 function:

Qt Code:
  1. quint32 EustiaTools::toUint32(QByteArray array, uint offStart)
  2. {
  3. return(quint32)((array[offStart+3] << 24) | (array[offStart+2] << 16) | (array[offStart+1] << 8) | (array[offStart]));
  4. }
To copy to clipboard, switch view to plain text mode 

My problem probably lies in this line:

Qt Code:
  1. quint32 curr = fragment[dwptr];
To copy to clipboard, switch view to plain text mode 

And in function toUint32 too.
I checked and my curr before for loop equals 4294967272 when currentDw from C# equals 232.
I changed type of curr from quint32 to int and then curr equals -24.

How to repair that?

Sorry for my bad english.
Thanks in advance.