Results 1 to 1 of 1

Thread: QString comparison gives wierd crash

  1. #1
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QString comparison gives wierd crash

    Hello

    I get this strange crash when using toAscii() on a QString.
    This is the output from the debugger:
    Qt Code:
    1. 0 QTextCodec::fromUnicode qtextcodec.cpp 1189
    2. 1 QChar::toAscii qchar.cpp 1261
    3. 2 OutputMessage::addString OutputMessage.cpp 62
    4. 3 Client::handleFirstPacket Client.cpp 87
    5. 4 Client::handleMessage Client.cpp 38
    6. 5 Client::listen Client.cpp 26
    7. ... <More>
    To copy to clipboard, switch view to plain text mode 

    This is the code that causes the crash:
    Qt Code:
    1. void OutputMessage::addString(const QString& value)
    2. {
    3. addU16(value.length());
    4. for(QString::const_iterator it = value.begin(); it != value.end(); it++)
    5. addByte((*it).toAscii());
    6. }
    To copy to clipboard, switch view to plain text mode 

    But I don't always get this crash. I found out that I only get it when I compare a QString with a (const char?) string.
    For example: if I add this piece of code (anywhere in my application)
    Qt Code:
    1. QString str = "test";
    2. bool result = (str == "test");
    To copy to clipboard, switch view to plain text mode 
    then it causes the crash. If I remove that piece of code, then the crash doesn't occur and everything runs fine!

    Help would be appreciated!
    Gillis

    Edit
    When I use QString::localeAwareCompare instead of ==, it causes no crash. But I want to use ==, how can I do this? What am I doing wrong?
    Last edited by supergillis; 1st June 2009 at 22:52.

Similar Threads

  1. Qy 4.4.3 MySQL driver failed
    By pamalite in forum Installation and Deployment
    Replies: 2
    Last Post: 23rd January 2010, 01:09
  2. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  3. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 14:28
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59

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.