QString unsigned char* 的转换
QString -> unsigned char* :
QString str = "ABCD";
int length = str.length();
unsigned char* sequence = NULL;
sequence =(unsigned char*)qstrdup(str.toAscii().constData());
delete[] sequence;
- sequence length = 5 --> ['A'] ['B'] ['C'] ['D'] ['/0']
- sequence is now "independant" from str
- sequence has to be deleted with -> delete [] sequence
QString -> char:
const QByteArray ba = string.toAscii(); // make ba const, because modifying this array might otherwise invalidate the pointer
const char* sequence = ba.constData(); // now sequence will remain valid within the current scope.
The call to toAscii() creates a temporary QByteArray which goes out of scope when used like this:
char *sequence = string.toAscii().constData();
// sequence is now a dangling pointer!
http://wxpjiujiang.blog.163.com/blog/static/203994030201292661134137/
QString unsigned char* 的转换的更多相关文章
- 将16进制unsigned char数组转换成整数
/** * 将unsigned char数组转换成long long数值 * {0x00 0x00 0x20 0x00}转换之后得到8192 * * @param str 数组 * @param le ...
- QString 和char数组转换(转)
在qt开发过程中经常遇到QString类和char数组进行转换,在此记录一下: QString->char数组 1 2 3 QString str="12fff"; QByt ...
- Qt unsigned char *与QString之间的相互转换
//unsiged char *转QString unsigned char *str = "fdd" ; char *str1 = (char *)str; QString s ...
- qt QString 与 int,char的转换
每次QString转换int或者char的时候都要查资料,记录一下,方便下次查看. 参考: http://blog.csdn.net/ei__nino/article/details/7297791 ...
- QString和char字符数组之间的转换(QTextCodec.toUnicode方法,特别注意\0的问题)
How can I convert a QString to char* and vice versa ?(trolltech) Answer:In order to convert a QStrin ...
- QStringLiteral(源代码里有一个通过构造函数产生的从const char*到QString的隐式转换,QStringLiteral字符串可以放在代码的任何地方,编译期直接生成utf16字符串,速度很快,体积变大)
原作者: Olivier Goffart 点击打开链接http://woboq.com/blog/qstringliteral.html 译者: zzjin 点击打开链接http://www.tuic ...
- 打印不同对象的字节表示 ( 对int*强制转换成unsigned char*的理解 )
此文章参考<深入理解计算机系统>P31. 先看如下代码: 12345的十六进制表示为:0x00003039 #include <stdio.h> int main() { ; ...
- QString和char字符串数组之间的转换 (转)
做串口通信时,碰到这样的问题,在Qt的界面中,我用QLineEdit对象负责显示发送和接收的文本,对其中的数据进行读取和显示使用的数据类型都是QString:但是,在对串口设备进行读写时,数据使用的形 ...
- QT:QString、QByteArray和char *的转换 【转载】
原文网址:http://blog.csdn.net/light1028/article/details/7899541 第一种,数据流的方式,这里只说从QByteArray转向QString. QBy ...
随机推荐
- 编程算法 - 背包问题(三种动态规划) 代码(C)
背包问题(三种动态规划) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目參考: http://blog.csdn.net/caroline_wen ...
- android隐藏显示小键盘
记录一下开发中虚拟键盘的使用,fragment和activity中不同的使用 fragment下点击其它位置隐藏小键盘,复制到initView()方法中 view.setOnTouchListener ...
- QList介绍(QList比QVector更快,这是由它们在内存中的存储方式决定的。QStringList是在QList的基础上针对字符串提供额外的函数。at()操作比操作符[]更快,因为它不需要深度复制)非常实用
FROM:http://apps.hi.baidu.com/share/detail/33517814 今天做项目时,需要用到QList来存储一组点.为此,我对QList类的说明进行了如下翻译. QL ...
- vector删,erase和remove难怪--【STL】
供vector使用容器.通常只是一个简单的遍历查找,其他操作已执行,这不是,今天,稍有不慎. erase方法的操作是将此时的节点删除,然后指向被删除节点的下一个: 如对数据1 6 6 4 7; #in ...
- WPF内实现与串口发送数据和接收数据
原文:WPF内实现与串口发送数据和接收数据 与串口发送数据和接收数据,在此作一个简单的Demo.此Demo可以实现按下硬件按钮,灯亮,发送灯状态数据过来.并且可以实现几个灯同时亮,发送灯的状态数据过来 ...
- Excel 2013永久取消超链接
原文:Excel 2013永久取消超链接 在使用Excel的过程中,Excel会自动将网址转换为超链接,操作不当,容易误点,引起不必要的错误, 那么本篇博客就总结下如何在Excel 2013里永久取消 ...
- WPF获取读取电脑指定文件夹中的指定文件的地址
//保存指定文件夹中的指定文件的地址 string List<string> mListUri = new List<string>(); //文件夹地址 string fol ...
- pandas 学习(二)—— pandas 下的常用函数
import pandas as pd; 1. 数据处理函数 pd.isnull()/pd.notnull():用于检测缺失数据: 2. 辅助函数 pd.to_datetime() 3. Series ...
- jupyter_远程安装&问题
安装: https://jupyter.readthedocs.io/en/latest/install.html#install 配置 Ubuntu 16.04 LTS 配置 Jupyter not ...
- 好用的Markdown 编辑器及工具
Markdown 是 2004 年由 John Gruberis 设计和开发的纯文本格式的语法,所以通过同一个名字它可以使用工具来转换成 HTML.readme 文件,在线论坛编写消息和快速创建富文本 ...