Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How convert Qsting to const char * ?

    General and Desktop
    3
    4
    1181
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tmtt66 last edited by

      how convert Qsting to const char * on that support unicode format?

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @
        QString string("blah blah");

        const char *raw = string.toUtf8().constData();
        @

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • Q
          QtRoS last edited by

          For UNICODE string I recommend the using of wchar_t* instead of char*. Or even QChar*. You can get it with data() method (note that size of QChar is 2 bytes like wchar_t in most of OS).

          But if you want raw bytes - you must receive QByteArray first with one of methods like toUtf8 or toLatin1.

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            Quoting Unicode 4.0:
            [quote]The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.[/quote]

            In any case, just as QtRoS hinted, you should stick qith Qt stuff as much as possible, as it's guaranteed to be cross-platform.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • First post
              Last post