Results 1 to 2 of 2

Thread: QByteArray char to int

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QByteArray char to int

    Quote Originally Posted by pdoria View Post
    in251 holds the value: "J[²

    This piece of code:
    Qt Code:
    1. bool ok;
    2. msgTime = in251.left(4).toUInt(&ok);
    3. if (!ok) printf ("Conversion ERROR!\r\n" );
    To copy to clipboard, switch view to plain text mode 

    always returns "Conversion error" and msgTime, of course, is set to zero.

    Why can't .toUint() convert those bytes to an int?
    ? Have you looked what in251.left(4) gives you back if the value of in251 is "J[²"? That can't work. Use QString::number() to convert a number in a string/byte array!
    Qt Code:
    1. qWarning() << QString::number(input251).left(4).toInt();
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Lykurg for this useful post:

    pdoria (16th July 2009)

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 20:48
  2. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 21:53
  3. char * problem
    By eleanor in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2008, 14:06
  4. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49
  5. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01

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
  •  
Qt is a trademark of The Qt Company.