I want to store items of QString
data in uint32_t Test[]
array. E.g. If I have QString data = {1,'A','C',9,8,.....}
as input than at output I want to have uint32_t Test = {1,'A','C',9,8,.....}
It's not complicated at all. Each QChar
is a thin wrapper around uint16_t
. All you need to do is to convert those to uint32_t
and you're done.
QVector<uint32_t> convert(const QString & str) {
QVector<uint32_t> output;
output.reserve(str.size());
for (auto c : str)
output.append(c.unicode());
return output;
}
void user(const uint32_t *, size_t size);
void test(const QString & str) {
auto const data = convert(str);
user(data.data(), size_t(data.size());
}
Of course it might be that you have wrong assumptions about the meaning of uint32_t
. The code above assumes that the user
expects UTF16 code units. It's more likely, though, that user
expects UTF32 code units, i.e. each uint32_t
represents exactly one Unicode code point.
In the latter case, you have to convert conjugate pairs of UTF16 code units to single UTF32 code units:
QVector<uint32_t> convert(const QString & str) {
return str.toUcs4();
}
Note that code point and code unit have specific meanings and are not synonymous.