Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: How to convert QString to std::string or char*?

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QString to std::string or char*?

    Why am I to explain someone elses statements?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    Quote Originally Posted by wysota View Post
    Why am I to explain someone elses statements?
    Yep thass true.
    I just posted that because of this post. So I though you guys means same.
    Quote Originally Posted by MrDeath View Post
    i was trying to say the same thing... ummm.. my english..
    After this thread I becomes.
    ME = ME - UTF.

  3. #23
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    Quote Originally Posted by wysota View Post
    "const char *" in C/C++ is "an array of 8bit values" so anything can go there. Its Qt equivalent is QByteArray. How the data stored in a particular const char * is interpreted is another story (that's why you have the "size" parameter here). UTF-8 strings CAN contain 0x00 values - but only if you directly place them there yourself. So in 99.9% of the cases keeping a utf-8 string in a C byte array without also keeping its size is fine.
    Other way to go around is serialization. He write the software he know what he can expect. For example the integer may vary on differend CPU's and OSes but thats why Qt provide to us qint8, qint16, qint32, qint64. In this way we can guarantee that the size of bytes will be fixed. So lets say that even he do not have 0x00 on the end of the utf-8 string, he can use other methods around. For example his own protocol, lets say he knows that the first 2 bytes that come are the length of the string, then he will know how much to continue to read further. I know that you are aware of this, I just point it out to make the thing clear( and a bit offtopic ).

    Ontopic: By my opinion the function in the API that yangyunzhao is talking about does not recognize utf-8.

  4. #24
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    Quote Originally Posted by The Storm View Post
    Ontopic: By my opinion the function in the API that yangyunzhao is talking about does not recognize utf-8.
    But yangyunzhao want to pass chinese string to API.

  5. #25
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    Quote Originally Posted by yogeshgokul View Post
    But yangyunzhao want to pass chinese string to API.
    btw its called Mandarian and not chinese... its like calling "indian" for hindi..

  6. #26
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    Quote Originally Posted by MrDeath View Post
    btw its called Mandarian and not chinese... its like calling "indian" for hindi..
    I am not bothering because the starter(yangyunzhao) mentioned term Chinese. And rest I don't care.
    Better see this and don't forget to pay your kind attention on bold letters.
    Quote Originally Posted by yangyunzhao View Post
    But if my QString has chinses character, I cannot conver it to std::string or char*.

  7. #27
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QString to std::string or char*?

    buhuhuhuhu... this thread has killed all my reputation

Similar Threads

  1. Getting std::string object from QString object ( qt3)
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 28th March 2013, 21:09
  2. convert from QString to char[sizeof(...)]
    By adamatic in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2011, 10:05
  3. convert QString to QByteArray
    By morgana in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2011, 14:33
  4. File rename detection
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 16:22
  5. convert QString to int
    By mattia in forum Newbie
    Replies: 2
    Last Post: 4th January 2008, 10:10

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.