Safe variant:
QString qt_mac_NSStringToQString
(const NSString
*nsstr
) {
NSRange range;
range.location = 0;
range.length = [nsstr length];
unichar *chars = new unichar[range.location];
[nsstr getCharacters:chars range:range];
delete chars;
return result;
}
QString qt_mac_NSStringToQString(const NSString *nsstr)
{
NSRange range;
range.location = 0;
range.length = [nsstr length];
QString result(range.length, QChar(0));
unichar *chars = new unichar[range.location];
[nsstr getCharacters:chars range:range];
QString result = QString::fromUtf16(chars, range.length);
delete chars;
return result;
}
To copy to clipboard, switch view to plain text mode
Unsafe variant (a little faster):
QString qt_mac_NSStringToQString
(const NSString
*nsstr
) {
NSRange range;
range.location = 0;
range.length = [nsstr length];
unichar *chars = reinterpret_cast<unichar *>(result.data())
[nsstr getCharacters:chars range:range];
return result;
}
QString qt_mac_NSStringToQString(const NSString *nsstr)
{
NSRange range;
range.location = 0;
range.length = [nsstr length];
QString result(range.length, QChar(0));
unichar *chars = reinterpret_cast<unichar *>(result.data())
[nsstr getCharacters:chars range:range];
return result;
}
To copy to clipboard, switch view to plain text mode
Any suggestions?
Bookmarks