char*转为const QString &name
时间: 2023-12-23 18:05:08 浏览: 43
可以使用QString的构造函数将char*转换为QString,然后再将QString转换为const QString &。示例代码如下:
```cpp
char* name = "John";
const QString &nameStr = QString(name);
```
这里将char*类型的name转换为QString类型的nameStr,并且使用了const引用来避免不必要的拷贝。
相关问题
error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘const char*’ [-fpermissive] cameraList.append(QString::fromUtf8(input.name)); ~~~~~~^~~~
这个错误是因为你试图将一个无符号字符指针(__u8*)转换成一个常量字符指针(const char*),而这种转换是不允许的。解决这个问题的方法是使用QString的fromUtf8()函数,它可以将一个以UTF-8编码的字符数组转换成一个QString对象。你可以这样修改代码:
cameraList.append(QString::fromUtf8(input.name));
error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘const char*’ [-fpermissive] cameraList.append(QString::fromLocal8Bit(input.name)); ~~~~~~^~~~
这个错误是因为你试图将一个无符号字符指针(__u8*)转换成一个常量字符指针(const char*),而这种转换是不允许的。解决这个问题的方法是使用QString的fromUtf8()函数,它可以将一个以UTF-8编码的字符数组转换成一个QString对象。你可以这样修改代码:
cameraList.append(QString::fromUtf8(input.name));
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)