[Qt学习篇]小品QIODevice::Text参数

时间:2014-08-22 17:49:49   收藏:0   阅读:519
小品QIODevice::Text参数:
QIODevice::Text
0x0010
使用该选项后:
对于读:end-of-line结束符被转译为‘\n‘;
对于写:end-of-line结束符被转本地编码方式对应的字符。比如,在Win32下,是‘\r\n‘
在使用QIODevice::Text选项读写二进制文件时,由于经过上述转译,造成读写数据不一致,测试示例如下:
 if (!fileRead.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "file open error!\r\n";
        //return (0);
 }
 if (!fileWrite.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qDebug() << "file not exist!\r\n";
 }
bubuko.com,布布扣
可知,原二进制文件中的0x0D被视作结束符,写的时候忽略;0x0A被转译为Win32下的0x0D 0x0A(\r\n)
去掉QIODevice::Text选项后,读写的数据是一的(测试数据量8k多字节):
if (!fileRead.open(QIODevice::ReadOnly)) {
        qDebug() << "file open error!\r\n";
        //return (0);
    }
    if (!fileWrite.open(QIODevice::WriteOnly)) {
        qDebug() << "file not exist!\r\n";
    }
bubuko.com,布布扣

原文:http://blog.csdn.net/u013686019/article/details/38759961

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!