Qt下QByteArray的使用
来源:互联网 发布:qq管家软件收录 编辑:程序博客网 时间:2024/06/03 21:35
今天遇到一个问题,想要实现一种功能:在QLineEdit中书写16进制字符串比如 00 01 ff,然后保存为16进制转换后的字节形式到内存中,然后在文件中进行查找字符串匹配,后来发现QByteArray QByteArray::fromHex(const QByteArray & hexEncoded)函数可以实现这个功能。
QByteArray QByteArray::fromHex(const QByteArray & hexEncoded)
Returns a decoded copy of the hex encoded array hexEncoded. Input is not checked for validity; invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.
For example:
QByteArray text = QByteArray::fromHex("517420697320677265617421");text.data(); // returns "Qt is great!"
对于字符串匹配查找方面,我用的是泛型函数库algorithm中的search函数:
具体用法请到:http://www.cplusplus.com中查询,这里只给出例子:
// search algorithm example#include <iostream> // std::cout#include <algorithm> // std::search#include <vector> // std::vectorbool mypredicate (int i, int j) { return (i==j);}int main () { std::vector<int> haystack; // set some values: haystack: 10 20 30 40 50 60 70 80 90 for (int i=1; i<10; i++) haystack.push_back(i*10); // using default comparison: int needle1[] = {40,50,60,70}; std::vector<int>::iterator it; it = std::search (haystack.begin(), haystack.end(), needle1, needle1+4); if (it!=haystack.end()) std::cout << "needle1 found at position " << (it-haystack.begin()) << '\n'; else std::cout << "needle1 not found\n"; // using predicate comparison: int needle2[] = {20,30,50}; it = std::search (haystack.begin(), haystack.end(), needle2, needle2+3, mypredicate); if (it!=haystack.end()) std::cout << "needle2 found at position " << (it-haystack.begin()) << '\n'; else std::cout << "needle2 not found\n"; return 0;}
Output:
needle1 found at position 3
needle2 not found
0 0
- Qt下QByteArray的使用
- QT下int与QByteArray的转换
- QT下int与QByteArray的转换
- QT下int与QByteArray的转换
- (Qt)深受QByteArray的陷害
- Qt 中的QString和QByteArray 使用
- QT:QString、QByteArray和char *的转换
- QT:QString、QByteArray和char *的转换
- QT:QString、QByteArray和char *的转换
- QT:QString、QByteArray和char *的转换
- QT:QString、QByteArray和char *的转换。
- QT:QByteArray和QByteArray、char *
- Qt下正确在QByteArray中保存字节数据的方法
- Qt入门-QByteArray类
- Qt中QString,char,int,QByteArray之间的转换
- SQLITE数据库存储类对象 用到qt的QByteArray
- Qt中 Qstring 与QbyteArray的互相转换
- QT---QString,int,char,QByteArray之间的转换
- oracle length&vsize
- 欢迎使用CSDN-markdown编辑器
- Longest Common Prefix String们的最长公共序列
- 几个有用的网络相关的命令
- hdu4714(树形dp)
- Qt下QByteArray的使用
- 使用for循环打印输出1000以内的水仙花数
- OnGlobalLayoutListener获得一个视图的高度
- CentOS 企业级 ----Zabbix 搭建
- ConfigurationManager不存在
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- as使用夜神模拟器
- VS中添加lib文件,以及出现LINK : fatal error LNK1104: 无法打开文件:×××.lib的解决办法
- 利用wsdl.exe生成webservice代理类