const char* 转QString错误
来源:互联网 发布:人工智能企业排名 编辑:程序博客网 时间:2024/05/06 04:51
Qt帮助文件中对QString有一段说明:
As mentioned above, QString provides a lot of functions and operators that make it easy to interoperate with const char * strings. But this functionality is a double-edged sword: It makes QString more convenient to use if all strings are US-ASCII or Latin-1, but there is always the risk that an implicit conversion from or to const char * is done using the wrong 8-bit encoding. To minimize these risks, you can turn off these implicit conversions by defining the following two preprocessor symbols:
QT_NO_CAST_FROM_ASCII disables automatic conversions from C string literals and pointers to Unicode.
QT_NO_CAST_TO_ASCII disables automatic conversion from QString to C strings.
One way to define these preprocessor symbols globally for your application is to add the following entry to your qmake project file:
DEFINES += QT_NO_CAST_FROM_ASCII \
QT_NO_CAST_TO_ASCII
You then need to explicitly call fromUtf8(), fromLatin1(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1String class, for example:
QString url = QLatin1String("http://www.unicode.org/");
由此可以得到解决方案:
1.在工程文件(.pro文件)中添加上述蓝色标记的文字,保存
2.重新编译,这时在const char*转QString处会报错('QString::QString(const char*)' is private),参照绿色标记的例子进行修改即可。
更多详情参见Qt中有关QString类的帮助文档。
As mentioned above, QString provides a lot of functions and operators that make it easy to interoperate with const char * strings. But this functionality is a double-edged sword: It makes QString more convenient to use if all strings are US-ASCII or Latin-1, but there is always the risk that an implicit conversion from or to const char * is done using the wrong 8-bit encoding. To minimize these risks, you can turn off these implicit conversions by defining the following two preprocessor symbols:
QT_NO_CAST_FROM_ASCII disables automatic conversions from C string literals and pointers to Unicode.
QT_NO_CAST_TO_ASCII disables automatic conversion from QString to C strings.
One way to define these preprocessor symbols globally for your application is to add the following entry to your qmake project file:
DEFINES += QT_NO_CAST_FROM_ASCII \
QT_NO_CAST_TO_ASCII
You then need to explicitly call fromUtf8(), fromLatin1(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1String class, for example:
QString url = QLatin1String("http://www.unicode.org/");
由此可以得到解决方案:
1.在工程文件(.pro文件)中添加上述蓝色标记的文字,保存
2.重新编译,这时在const char*转QString处会报错('QString::QString(const char*)' is private),参照绿色标记的例子进行修改即可。
更多详情参见Qt中有关QString类的帮助文档。
0 0
- const char* 转QString错误
- 错误记录:QString转const char* 问题
- "QString" to "const char*"
- QT类型转换 QString转const char*,QString转u_short
- 错误:cannot convert 'QString' to 'const char*' for argument '1' to 'int system(const char*)'
- QString & QString::sprintf(const char * cformat, ...)应用
- QT中QString转const char *的问题
- QString类型转化成const char *类型
- Qt QString类型 转换为 const char*
- QString类型转化成const char *类型
- QT QString转Char *
- QString转char*
- QString转char*
- QString转Char*字符串
- 关于QString转char *
- QString转char*
- char* 字符串转QString
- QT QString 转 char*
- 线性光耦 和 非线性光耦
- cocos2d js jsb XMLHttpRequest 中文乱码
- windows eclipse运行mapreduce遇到权限问题该如何解决
- CentOS添加Root权限(超级用户)用户方法|su,sudo命令详解
- 我是李小龙,阿打!!!!!!!
- const char* 转QString错误
- fix questions
- 导购网站:差异化决定生死
- 以旧换新,iPhone5s免费拿
- iOS MD5加密
- Struts2源码学习(一)准备工作
- 在smarty中使用if else
- hadoop作业调优参数整理及原理
- 面试不是意味着给解决方案,有时候我们也应该质疑问题