I wrote some code that tries to extract an integer 100 out of this string:

"AB,SH#100 \r\n\0"

but the toInt() always fails; i.e. 0 is returned from toInt(). Note that the original data came in from QByteArray(). I currently use append() to convert from QByteArray to QString.

As a separate question, is there a better way to convert QByteArray to QString than QString::append()?


Qt Code:
  1. QByteArray bte = "AB,SH#100 \r\n\0";
  2. QString test;
  3. test.append( bte );
  4. QStringList list = test.split( "," );
  5. QStringList tmp = list.filter( "SH#" );
  6.  
  7. tmp[0].remove( 0, 3 );
  8. int value = test.toInt();
To copy to clipboard, switch view to plain text mode 

Thanks!