char转QString
时间: 2024-01-03 12:49:33 浏览: 15
将char数组转换为QString,可以使用QString的构造函数进行转换。具体代码如下:
```
char* charArray = "Hello world";
QString qStr = QString::fromLatin1(charArray);
```
fromLatin1()函数可以将char数组转换为QString类型。如果char数组中包含中文字符,则可以使用fromLocal8Bit()函数进行转换。
相关问题
char转qstring
可以使用QString的构造函数将char数组转换为QString,如下所示:
```cpp
char str[] = "Hello World";
QString qstr = QString::fromLatin1(str);
```
其中,fromLatin1()函数将char数组转换为Latin-1编码的QString。如果需要转换为其他编码格式的QString,可以使用fromLocal8Bit()、fromUtf8()等函数。
qt char转qstring
Qt中char转QString可以使用QString的构造函数或者静态转换函数。如果char*中含有中文字符,可以先将char*转换为std::string类型,然后再将std::string转换为const char*,再使用QString的构造函数转换为QString类型。
方法一:
char* ch = "acuity";
QString str(ch);
方法二:
char* ch = "acuity";
std::string str(ch);
const char* c_str = str.c_str();
QString qstr(c_str);
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)