Results 1 to 6 of 6

Thread: size of QChar

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default size of QChar

    hi
    The QChar doc says
    The QChar class provides a 16-bit Unicode character.
    But it seems a single character is stored as one byte.
    Qt Code:
    1. QChar ch('a');
    2. QByteArray arr(QString(ch).toAscii());
    3. qDebug()<<arr.size();//The OutPut is 1.
    To copy to clipboard, switch view to plain text mode 
    I had expected the size to be 2 bytes.

  2. #2
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: size of QChar

    From QString::toAscii:

    Returns an 8-bit ASCII representation of the string as a QByteArray.

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: size of QChar

    i have already used it in example of first post.

  4. #4
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: size of QChar

    I mentioned it to explain why size() returns 1.

    QString::toAscii() returns the 8-bit ascii representation of the character.

    So
    Qt Code:
    1. QString(ch).toAscii();
    To copy to clipboard, switch view to plain text mode 
    takes your 2-byte Unicode character and returns the 1-byte ascii version of it, hence arr.size() gives 1.

  5. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: size of QChar

    takes your 2-byte Unicode character and returns the 1-byte ascii version of it
    where is the other byte.

  6. #6
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: size of QChar

    Quote Originally Posted by babu198649 View Post
    where is the other byte.
    Gone :-)
    Information is lost in the conversion.

Similar Threads

  1. How to find best size for QTableWidget?
    By plamkata in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2008, 19:07
  2. qPEditor - the editor for the programmer.
    By mik-protasov in forum Qt-based Software
    Replies: 10
    Last Post: 22nd July 2008, 09:21
  3. QT-wince and QHttp::readAll() trouble....
    By AcerExtensa in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 12th June 2008, 09:40
  4. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.