字符数组的内容复制到Qt中为QString [英] Copying the content of a character array to a QString in Qt

查看:725
本文介绍了字符数组的内容复制到Qt中为QString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在任何运行可以有不同长度的字符指针。例如:

I have a character pointer that in any run can have different length. For example:

char*  myChar;

在一个运行其含量可的的而在另一个运行它,可以的再见

In one run its content can be "Hi" and in another run it can be "Bye".

我想 myChar 的内容复制到QString的,例如,如果我有:

I want to copy the content of myChar to a QString, for example if I have:

QString myString;

我想 myChar 中的内容复制到的myString ;我该怎么办呢?

I want to copy the content of myChar to myString; how can I do that?

推荐答案

使用的QString :: fromLatin1(为const char *)的QString :: fromLocal8Bit(为const char *)的QString :: fromUtf8(为const char *)为宜。请注意,你不能只是复制数据,因为将QString包含16位的Uni code字符。它总是需要去code中的8位重presentation。

Use QString::fromLatin1(const char*), QString::fromLocal8Bit(const char*) or QString::fromUtf8(const char*) as appropriate. Note that you can't just copy the data because QStrings contain 16-bit Unicode characters. It will always need to decode the 8-bit representation.

这篇关于字符数组的内容复制到Qt中为QString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆