Hi, I'm trying to rewrite some functions from C# to Qt, but something is going wrong. I dont know why...
Could somebody look in my code please ?

Function should convert byte to uint:

Orginal C# function:
Qt Code:
  1. public static String ByteToString(byte[] crc)
  2. {
  3. String ret = "";
  4. if(crc != null){
  5. ret = ((int)crc[0]).ToString("X2");
  6. ret += ((int)crc[1]).ToString("X2");
  7. ret += ((int)crc[2]).ToString("X2");
  8. ret += ((int)crc[3]).ToString("X2");
  9. }
  10. return ret;
  11. }
  12.  
  13. public static uint ByteTouInt(byte[] crc){
  14. if(crc != null) {
  15. return Convert.ToUInt32(Tools.ByteToString(crc), 16);
  16. }else{
  17. return 0;
  18. }
  19. return 0;
  20. }
To copy to clipboard, switch view to plain text mode 

My function in Qt (First idea)
Qt Code:
  1. QString Tools::byteToString(byte *crc)
  2. {
  3. QString crc_string = "";
  4. if(sizeof crc < 4 || crc == NULL) {
  5. return "bad";
  6. }
  7. for(int i = 0; i < 4; i++) {
  8. crc_string += (QString::number((int)crc[i], 16).length() == 1) ? "0" + QString::number((int)crc[i], 16) : QString::number((int)crc[i], 16);
  9. }
  10. return crc_string.toUpper();
  11. }
  12.  
  13. inline uint byteToUInt(byte *crc) {
  14. return byteToString(crc).toUInt(NULL, 16);
  15. }
To copy to clipboard, switch view to plain text mode 

Second idea...
Qt Code:
  1. inline uint Tools::byteToUInt(byte *b)
  2. {
  3. uint val;
  4. ba.append(((const char*) b));
  5.  
  6. //val = (ba[1] << 8) | ba[0];
  7. memcpy(&val, ba.constData(), 2);
  8.  
  9. return val;
  10. }
To copy to clipboard, switch view to plain text mode 

Function returns different values, I'm not a author of C# code, so I've got problems to convert it properly.
To compile C# code I used this online IDE/compiler: http://www.tutorialspoint.com/compile_csharp_online.php

Thank You for any help and suggestions.