Angus Leeming a écrit :
Abdelrazak Younes <[EMAIL PROTECTED]> writes:
Edwin> the attached works for me
Edwin> -     Q3CString tmpstr = codec->fromUnicode(str);
Edwin> -     char const * tmpcstr = tmpstr;
Edwin> +     char const * tmpcstr = codec->fromUnicode(str).data();

Abdel> Maybe:
Abdel>       return codec->fromUnicode(str)[0];

Edwin>       return tmpcstr[0];
Edwin>  }

Abdel> This code does not seems very safe (no chech on Abdel> str emptyness) and it would have be probably changed Abdel> soon because of unicode work. But in the mean time
Abdel> I'd say put it in if it works...

No, please make it safe first.

Actually my version is safe because QTextCodec::fromUnicode(str) returns a QByteArray which always contain at least a \0 character. So go for it.

Initializing a std::string with a null char* is
always an error and will lead to a hard crash. The idiom to use is:

    char * foo = ...
    std::string bar = foo ? foo : std::string();

If memory serves, a similar idiom is needed by QString. (That may well be the
reason why Q3String was used.)

Agreed,
Abdel.

Reply via email to