QIODevice 类学习笔记
QIODevice 类学习笔记
Isaaccwoo 2015年12月10日
一、 简介
QIODevice用于对输入输出设备进行管理。输入设备有两种类型,一种是随机访问设备(Random-accessdevices),如文件、缓冲区等;另一种是时序设备(Sequential device),如网络、进程等。可以通过isSequential()函数分辨设备是哪种类型的。
二、 自定义类型
设备的打开方式:OpenMode
enum QIODevice::OpenModeFlag
flags QIODevice::OpenMode
Constant |
Value |
Description |
QIODevice::NotOpen |
0x0000 |
The device is not open. |
QIODevice::ReadOnly |
0x0001 |
The device is open for reading. |
QIODevice::WriteOnly |
0x0002 |
The device is open for writing. Note that this mode implies Truncate. |
QIODevice::ReadWrite |
ReadOnly | WriteOnly |
The device is open for reading and writing. |
QIODevice::Append |
0x0004 |
The device is opened in append mode so that all data is written to the end of the file. |
QIODevice::Truncate |
0x0008 |
If possible, the device is truncated before it is opened. All earlier contents of the device are lost. |
QIODevice::Text |
0x0010 |
When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32. |
QIODevice::Unbuffered |
0x0020 |
Any buffer in the device is bypassed. |
三、 正确的打开方式 输入输出设备的使用方法
1. 构造与析构
函数 |
说明 |
QIODevice() |
|
QIODevice(QObject * parent) |
|
~QIODevice() |
继承类需自行保证close() |
2. OpenMode
返回类型 |
函数 |
说明 |
OpenMode |
openMode() const |
QIODevice::OpenMode |
void [protected] |
setOpenMode(OpenMode openMode) |
|
bool |
isOpen() const |
QIODevice::NotOpen |
bool |
isReadable() const |
QIODevice::ReadOnly |
bool |
isWritable() const |
QIODevice::WriteOnly |
bool |
isTextModeEnabled() const |
QIODevice::Text |
void |
setTextModeEnabled(bool enabled) |
QIODevice::Text |
bool [virtual] |
isSequential() const |
3. 打开关闭设备
返回类型 |
函数 |
说明 |
bool [virtual] |
open(OpenMode mode) |
|
bool |
isOpen() const |
|
void [virtual] |
close() |
|
void [signal] |
aboutToClose() |
|
Bool [virtual] |
reset() |
重打开设备。 不适用于QIODevice::Text类设备。 |
4. 数据读写操作及控制
输入函数 |
||
返回类型 |
函数 |
说明 |
bool [virtual] |
waitForReadyRead(int msecs) |
等待可读 |
void [signal] |
readyRead() |
中断式可读 |
qint64 [virtual] |
bytesAvailable() const |
查询式可读 |
qint64 [protected] [pure virtual] |
readData(char * data, qint64 maxSize) |
读函数 |
qint64 |
read(char * data, qint64 maxSize) |
读 |
QByteArray |
read(qint64 maxSize) |
. |
qint64 |
peek(char * data, qint64 maxSize) |
“偷看” |
QByteArray |
peek(qint64 maxSize) |
. |
QByteArray |
readAll() |
读全部 |
bool [virtual] |
canReadLine() const |
可读行 |
qint64 [virtual] [protected] |
readLineData(char * data, qint64 maxSize) |
读行函数 |
qint64 |
readLine(char * data, qint64 maxSize) |
读行 (maxSize包括行结束字符) |
QByteArray |
readLine(qint64 maxSize = 0) |
读行 |
bool |
getChar(char * c) |
读char |
void |
ungetChar(char c) |
undo char |
void [signal] |
readChannelFinished() |
输入通道结束。 但此时可能仍有数据可读。 |
输出函数 |
||
返回类型 |
函数 |
说明 |
bool [virtual] |
waitForBytesWritten(int msecs) |
等待已写 |
void [signal] |
bytesWritten(qint64 bytes) |
中断式已写 |
qint64 [virtual] |
bytesToWrite() const |
查询式写完 |
qint64 [protected] [pure virtual] |
writeData(const char * data, qint64 maxSize) |
写函数 |
qint64 |
write(const char * data, qint64 maxSize) |
写 |
qint64 |
write(const char * data) |
. |
qint64 |
write(const QByteArray & byteArray) |
. |
bool |
putChar(char c) |
写char |
isSequential()不同有区别的函数 |
||
返回类型 |
函数 |
说明 |
qint64 [virtual] |
pos() const |
|
bool [virtual] |
seek(qint64 pos) |
|
qint64 [virtual] |
size() const |
随机访问设备为区域大小,时序设备为bytesAvailable() |
其他函数 |
||
返回类型 |
函数 |
说明 |
bool [virtual] |
atEnd() const |
|
QString |
errorString() const |
|
void [protected] |
setErrorString(const QString & str) |
注:qint64返回值一般原则为,错误返回-1,成功返回>=0
QIODevice 类学习笔记相关推荐
- Unity API常用方法和类学习笔记2
Unity API常用方法和类学习笔记2 ------Mathf & Input & Vector & Random 类Mathf 一.静态变量 print(Mathf.Deg ...
- Unity API常用方法和类学习笔记1
Unity API常用方法和类学习笔记1 ------主要构架(Unity-Engine.GameObject.Component) 事件 一.事件执行顺序 二.测试代码 using System.C ...
- QFrame类学习笔记
QFrame类学习笔记 参考:https://wenku.baidu.com/view/759c1af565ce050877321322.html https://doc.qt.io/qt-5/qfr ...
- 转载:C++ list 类学习笔记
声明:本文转自http://blog.csdn.net/whz_zb/article/details/6831817 双向循环链表list list是双向循环链表,,每一个元素都知道前面一个元素和后面 ...
- C# Console类学习笔记
Console.Write 表示向控制台直接写入字符串,不进行换行,可继续接着前面的字符写入. Console.WriteLine 表示向控制台写入字符串后换行. Console.Read 表示从控制 ...
- ThreadLocal类学习笔记
这个类在java1.2中就出现了,线程独有的变量(每个线程都有一份变量),使用它的好处之一就是可以少传许多参数. 在哪里用到它呢?有连接池的地方就有它的身影,连接池包括数据库连接池,网络连接池等. i ...
- Java常用类学习笔记
Date类 Date类是在Java中获取日期时间最简单的一个类,可以通过直接实例化对象的方式获得当前的日期时间.得到的日期时间是国外的格式.Date类没有什么特殊的用法,就是简单的获取当前的日期时间. ...
- 《快学Scala》第14章——模式匹配和样例类 学习笔记
Scala有一个十分强大的模式匹配机制,可以应用在很多场合:switch语句.类型查询,以及"析构"(获取复杂表达式中的不同部分).除此之外,Scala还提供了样例类,对模式匹配进 ...
- java calendar赋值_Java calendar类学习笔记
Java Calendar类 calendar类是abstract类,实际使用时实现特定的子类对象 创建一个代表当前日期的Calendar对象 Calendar ss=Calendar.getlnst ...
最新文章
- [Selenium]Eclipse hangs at 57% in debug mode with TestNG tests
- jQuery解决高度统一问题
- arm中断保护和恢复_ARM中断返回的详细分析
- Spring应用上下文 - - context
- 太极图正确画法_太极图的三种画法你知道吗?
- 一种被国人漠视的精神---狼的精神
- 初学JAVA随记——代码练习(二元一次方程)
- 计算机为什么要区别C盘,D盘,E盘等?
- 注意!恶意NPM包正在安装勒索软件和密码窃取木马
- mysql空指针异常处理_mysql 查询空指针异常
- 什么职业的人适合考PMP?(含PMP资料)
- html斜杠单元格,用斜杠拆分左侧单元格的html表
- html怎么设置border-radius,CSS border-radius 能做什么?
- 蓦然回首,你想要的就在这里
- 斯皮尔 皮尔森 肯德尔_pearson(皮尔逊), kendall(肯德尔)和spearman(斯伯曼斯皮尔曼)三种相关分析方法...
- 超详细的JavaScript对象分享,看完就会了
- 使用echarts将Excel的数据可视化
- 基于CTP的国内期货程序化交易之行情获取讲解
- 解决不同版本jar包引入问题,修改jar包包名
- ubuntu20.04禁止自动休眠的几种方式
热门文章
- 密码加密与微服务鉴权JWT
- javascript-由初速度和仰角求射程
- Centos7环境下编译安装Mysql
- 小波分析中的尺度函数与小波函数
- 如何解决Chrome无法访问ftp的问题
- OpenART mini 控制舵机
- Kali Linux2021.1安装详细教程
- “人工”智能框架下的PDF转Word试探
- 淮海工学院计算机学院项目,淮海工学院计算机工程学院-开放实验项目总结报告-××专业×××姓名.docx...
- layer.confirm快速点击会重复触发事件问题