qt之QTextStream

QTextStream 类 为读写文本数据提供了方便的接口

  

  

   QFile data(“output.txt”);

   If(data.open(QFIle::WriteOnly | QFile::Truncate))

   {

      QTextStream out(&data);

      Out << “Result” << qSetFieldWidth(10) << left << 3.14 << 2.7;

      // “Result:3.14       2.7” 

   }

 

 

QTextStream::QTextStream(QString * stringQIODevice::OpenMode openMode = QIODevice::ReadWrite)

 

构造一个QTextStream对象,用于操作string

 

QTextStream::QTextStream(QByteArray * arrayQIODevice::OpenMode openMode = QIODevice::ReadWrite)

构造一个QTextStream对象,用于操作array对象。

bool QTextStream::atEnd() const

 

如果QTextStream对象没有更多的数据,则返回true

 

 

自动检测unicode编码

 

QTextCodec * QTextStream::codec() const

 

返回QTextStream的当前编码解码器

 

QIODevice * QTextStream::device() const

 

返回当前与QTextStream关联的设备,如果没有设备与之关联则返回NULL

 

FieldAlignment QTextStream::fieldAlignment() const

 

返回当前的调整格式

 

int QTextStream::fieldWidth() const

返回当前字段宽度。

 

void QTextStream::flush()

刷新缓冲区,而这些缓冲区中保存的是待写入设备的数据

 

bool QTextStream::generateByteOrderMark() const

 

如果当前设置的字节顺序标记为utf编码解码器,则返回true,否则返回false

 

qint64 QTextStream::pos() const

 

返回当前在流中的位置,出错返回-1.

 

StartFragment:0000000127 EndFragment:0000001410

QString QTextStream::read(qint64 maxlen)

 

在流中读取maxlen个字符返回。

 

QString QTextStream::readAll()

 

读取流中的所有数据

 

QString QTextStream::readLine(qint64 maxlen = 0)

 

在流中读取一行 并返回

 

bool QTextStream::readLineInto(QString * lineqint64 maxlen = 0)

在流中读取一行到line

void QTextStream::resetStatus()

重置流的状态

 

 

bool QTextStream::seek(qint64 pos)

 

跳转到QTextStream流中pos位置。

void QTextStream::setCodec(QTextCodec * codec)

 

 

void QTextStream::setPadChar(QChar ch)

Sets the pad character to ch. The default value is the ASCII space character (' '), or QChar(0x20). This character is used to fill in the space in fields when generating text.

Example:

QString s;QTextStream out(&s);

out.setFieldWidth(10);

out.setFieldAlignment(QTextStream::AlignCenter);

out.setPadChar('-');

out << "Qt" << "rocks!";

The string s contains:

----Qt------rocks!--

 

 

 

 

 

 

 

QTextCodec支持的类型有

§ Big5

§ Big5-HKSCS

§ CP949

§ EUC-JP

§ EUC-KR

§ GB18030

§ HP-ROMAN8

§ IBM 850

§ IBM 866

§ IBM 874

§ ISO 2022-JP

§ ISO 8859-1 to 10

§ ISO 8859-13 to 16

§ Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml

§ KOI8-R

§ KOI8-U

§ Macintosh

§ Shift-JIS

§ TIS-620

§ TSCII

§ UTF-8

§ UTF-16

§ UTF-16BE

§ UTF-16LE

§ UTF-32

§ UTF-32BE

§ UTF-32LE

§ Windows-1250 to 1258

 

 

 

 

   

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值