当前位置:网站首页>QString转换char*
QString转换char*
2022-07-27 04:00:00 【立冲君也】
将 QString 转 char *,需要用到 QByteArray 类,QByteArray 类的说明详见 Qt 帮助文档。
因为 char * 最后都有一个’\0’作为结束符,而采用 QString::toLatin1() 时会在字符串后面加上’\0’。
QString str;
char* ch;
QByteArray ba = str.toLatin1(); // must
ch=ba.data();
这样就完成了 QString 向 char * 的转化。经测试程序运行时不会出现 bug。注意第3行,一定要加上,单独写,不可以 str.toLatin1().data() 这样一步完成,否则可能会出错。
边栏推荐
- The new Internet era has come. What new opportunities will Web 3.0 bring us
- Head detached from origin/... Causes push failure
- playwright网络爬虫实战案例分享
- 通信协议综述
- Shel automatically sets directory permissions
- JS modify the key value of the object array
- IIC 通信协议 (一)
- PX4模块设计之十二:High Resolution Timer设计
- els 兼容性DC、传递图片到窗口
- ISG指数显示,亚太区IT和商业服务市场在第二季度出现大幅下滑
猜你喜欢

JMeter learning notes 004-csv file line number control cycle times

Convolution neural network -- a detailed introduction to convolution of 24 bit color images

管理信息系统期末复习

Eureka-服务注册中心

卷积神经网络——24位彩色图像的卷积的详细介绍

好用的shell快捷键
![Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量](/img/ed/941276a15d1c4ab67d397fb3286022.png)
Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
![[C language] recursively explain the tower of Hanoi problem](/img/a6/bbf1f19fc2a663df155cca53f2538a.png)
[C language] recursively explain the tower of Hanoi problem

How to set user-defined display for Jiaming Watch

Final review of management information system
随机推荐
js三种遍历数组的方法:map、forEach、filter
State Hook
Deep analysis - dynamic memory management
Unity:Resource Merging、Static Batching、Dynamic Batching、GPU Instancing
佳明手表怎么设置用户定制显示
e.target与e.currentTarget的区别
【软件工程期末复习】知识点+大题详解(E-R图、数据流图、N-S盒图、状态图、活动图、用例图....)
微信小程序轮播图
els_ 画矩形、代码规划和备份
数据分析师岗位分析
Prometheus Node Exporter 常用监控指标
timestamp列使用varchar类型和使用date类型有什么区别?
The external symbol parsed by the method "public: virtual _ucdecl nvinfer1:: yololayerplugin:: ~yololayerplugin (void)" "public: virtual
How CentOS installs mysqldump
Ribbon load balancing strategy and configuration, lazy loading and hungry loading of ribbon
Word/excel has a fixed table size. When filling in the content, the table does not change with the cell content
Head detached from origin/... Causes push failure
F - Pre-order and In-order(Atcoder 255)
Ribbon load balancing principle and some source codes
ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter