• 12715阅读
  • 8回复

QString与QByteArray的区别 [复制链接]

上一主题 下一主题
离线asdfgsdgasd
 
只看楼主 倒序阅读 楼主  发表于: 2010-05-30
它们最大的区别是什么。
离线dbzhang800

只看该作者 1楼 发表于: 2010-05-30
不妨自己先去看QByteArray 和 QString 的 manual

建议阅读 “提问的智慧”
离线asdfgsdgasd
只看该作者 2楼 发表于: 2010-05-30
回 1楼(dbzhang800) 的帖子
怎么又是你 !!! 我问他们的功能都差不多  有什么区别
离线tongxueq

只看该作者 3楼 发表于: 2010-05-30
故名思意
相对于一段内存里的数据来说
QString 是用来处理字符串的 遇到 '/0'就结束了
QByteArray  是将每个字节都读取出来,把它当数组来使用,包括'/0'
离线dbzhang800

只看该作者 4楼 发表于: 2010-05-30
Re:回 1楼(dbzhang800) 的帖子
引用第2楼asdfgsdgasd于2010-05-30 18:53发表的 回 1楼(dbzhang800) 的帖子 :
怎么又是你 !!! 我问他们的功能都差不多  有什么区别


我前面提到了,建议阅读Qt的manual 和 “提问的智慧”。

特别想这种manual中的现成的东西,其他人很难讲的这么细,也很难这么权威:


Detailed Description

The QByteArray class provides an array of bytes.

QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings. Using QByteArray is much more convenient than using const char *. Behind the scenes, it always ensures that the data is followed by a '\0' terminator, and uses implicit sharing (copy-on-write) to reduce memory usage and avoid needless copying of data.

In addition to QByteArray, Qt also provides the QString class to store string data. For most purposes, QString is the class you want to use. It stores 16-bit Unicode characters, making it easy to store non-ASCII/non-Latin-1 characters in your application. Furthermore, QString is used throughout in the Qt API. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).

...



Detailed Description

The QString class provides a Unicode character string.

QString stores a string of 16-bit QChars, where each QChar corresponds one Unicode 4.0 character. (Unicode characters with code values above 65535 are stored using surrogate pairs, i.e., two consecutive QChars.)

Unicode is an international standard that supports most of the writing systems in use today. It is a superset of US-ASCII (ANSI X3.4-1986) and Latin-1 (ISO 8859-1), and all the US-ASCII/Latin-1 characters are available at the same code positions.

Behind the scenes, QString uses implicit sharing (copy-on-write) to reduce memory usage and to avoid the needless copying of data. This also helps reduce the inherent overhead of storing 16-bit characters instead of 8-bit characters.

In addition to QString, Qt also provides the QByteArray class to store raw bytes and traditional 8-bit '\0'-terminated strings. For most purposes, QString is the class you want to use. It is used throughout the Qt API, and the Unicode support ensures that your applications will be easy to translate if you want to expand your application's market at some point. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).





离线numen

只看该作者 5楼 发表于: 2010-05-31
支持楼上的,希望某些人还是认真看看manual再提问
欢迎访问我的blog:
http://www.cnblogs.com/baizx
离线asdfgsdgasd
只看该作者 6楼 发表于: 2010-06-10
回 5楼(numen) 的帖子
知道了  干嘛哪么多人损我。。。
谢谢帮我吧问题解决了
离线wd007

只看该作者 7楼 发表于: 2010-06-11
没有关系的,有问题时第一选择是查阅文档,或者是调试程序。

实在不行时,再问别人。这样能得到锻炼。
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线asdfgsdgasd
只看该作者 8楼 发表于: 2010-06-11
恩啊  我也知道 你知道文档的英语翻译我不是很明白
快速回复
限100 字节
 
上一个 下一个