qt之QTextStream

来源:互联网 发布:淘宝网无线话筒 编辑:程序博客网 时间:2024/04/30 02:40

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

 

 

 

 

   

 

0 0
原创粉丝点击