用于读写文件,但可以多线程调用,通过信号槽传递结果
更多...
#include <DATextReadWriter.h>
|
| enum | ErrorCode {
NoError = QFileDevice::NoError
, ReadError = QFileDevice::ReadError
, WriteError = QFileDevice::WriteError
, FatalError = QFileDevice::FatalError
,
ResourceError = QFileDevice::ResourceError
, OpenError = QFileDevice::OpenError
, AbortError = QFileDevice::AbortError
, TimeOutError = QFileDevice::TimeOutError
,
UnspecifiedError = QFileDevice::UnspecifiedError
, RemoveError = QFileDevice::RemoveError
, RenameError = QFileDevice::RenameError
, PositionError = QFileDevice::PositionError
,
ResizeError = QFileDevice::ResizeError
, PermissionsError = QFileDevice::PermissionsError
, CopyError = QFileDevice::CopyError
, UserTerminate
} |
| |
|
using | StringFun = std::function< QString(const QString &) > |
| |
|
|
void | startReadText () |
| | 开始读取文本 可以在主线程直接调用而不阻塞
|
| |
| void | appendText (const QString &text) |
| | 插入文本
|
| |
| void | appendLine (const QString &text) |
| | 插入一行文本
|
| |
| bool | flush () |
| | Flushes any buffered data to the file. Returns true if successful; otherwise returns false.
|
| |
| void | operatorFile (std::function< void(QFile *) > fun) |
| | 传入一个操作QFile的函数指针,此函数指针用于操作内部保存的QFile
|
| |
|
| void | readComplete (const QString &str, bool reachEnd) |
| | 完成一次读取会返回此信号
|
| |
|
void | startedReadText () |
| | 开始读取发射的信号,读取完成会发射readComplete信号
|
| |
| void | finished (int errcode) |
| | 完成信号
|
| |
|
|
| DATextReadWriter (QObject *parent=nullptr) |
| |
|
void | setFileName (const QString &name) |
| |
| int | getTotalReadLineCount () const |
| | 总共读取的行数,当读取到达此行后会发射readAllComplete
|
| |
| void | setTotalReadLineCount (int totalReadLineCount) |
| | 设置总共读取的行数,当读取到达此行后会发射readAllComplete
|
| |
| int | getReadOnceLineCount () const |
| | 一次读取的行数,当开始读取时达到这个行数后会发射readComplete, 继续往下读取(没有超过m_totalReadLineCount的行数),再次达到m_readOnceLineCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的行数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
|
| |
| void | setReadOnceLineCount (int readOnceLineCount) |
| | 设置一次读取的行数,但开始读取时达到这个行数后会发射readComplete, 继续往下读取(没有超过m_totalReadLineCount的行数),再次达到m_readOnceLineCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的行数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
|
| |
| int | getTotalReadCharCount () const |
| | 一次读取的字符数,当开始读取时达到这个字符数后会发射readComplete, 继续往下读取(没有超过m_totalReadCharCount的字符数),再次达到m_readOnceCharCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的字符数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
|
| |
| void | setTotalReadCharCount (int totalReadCharCount) |
| | 设置一次读取的字符数,当开始读取时达到这个字符数后会发射readComplete, 继续往下读取(没有超过m_totalReadCharCount的字符数),再次达到m_readOnceCharCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的字符数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
|
| |
| int | getReadOnceCharCount () const |
| | 总共读取的字符数,当读取到达此字符数后会发射readAllComplete
|
| |
| void | setReadOnceCharCount (int readOnceCharCount) |
| | 设置总共读取的字符数,当读取到达此字符数后会发射readAllComplete
|
| |
| void | setSkipHeader (std::size_t v) |
| | 设置跳过的行数 此函数仅仅对读取有效
|
| |
|
int | getSkipHeader () const |
| |
| bool | isOpen () const |
| | 文件是否已经打开
|
| |
| bool | open (QIODevice::OpenMode mode=QIODevice::ReadOnly|QIODevice::Text) |
| | 打开文件
|
| |
| QString | getLastErrorString () const |
| | 最后一次错误信息
|
| |
|
QString | getCodec () const |
| |
|
void | setCodec (const QString &codec) |
| |
| void | setStringFun (const StringFun &fun) |
| | 处理每次读取的函数指针,默认为nullptr
|
| |
|
void | setStopRead (bool stopRead) |
| |
用于读写文件,但可以多线程调用,通过信号槽传递结果
- 作者
- czy
- 日期
- 20170408
◆ ErrorCode
| 枚举值 |
|---|
| NoError | No error occurred.
|
| ReadError | An error occurred when reading from the file.
|
| WriteError | An error occurred when writing to the file.
|
| FatalError | A fatal error occurred.
|
| ResourceError | Out of resources (e.g., too many open files, out of memory, etc.)
|
| OpenError | The file could not be opened.
|
| AbortError | The operation was aborted.
|
| TimeOutError | A timeout occurred.
|
| UnspecifiedError | An unspecified error occurred.
|
| RemoveError | The file could not be removed.
|
| RenameError | The file could not be renamed.
|
| PositionError | The position in the file could not be changed.
|
| ResizeError | The file could not be resized.
|
| PermissionsError | The file could not be accessed.
|
| CopyError | The file could not be copied.
|
| UserTerminate | 用户中断
|
◆ appendLine
| void DA::DATextReadWriter::appendLine |
( |
const QString & |
text | ) |
|
|
slot |
◆ appendText
| void DA::DATextReadWriter::appendText |
( |
const QString & |
text | ) |
|
|
slot |
◆ errorCodeToString()
| QString DA::DATextReadWriter::errorCodeToString |
( |
ErrorCode |
c | ) |
|
|
static |
◆ finished
| void DA::DATextReadWriter::finished |
( |
int |
errcode | ) |
|
|
signal |
◆ flush
| bool DA::DATextReadWriter::flush |
( |
| ) |
|
|
slot |
Flushes any buffered data to the file. Returns true if successful; otherwise returns false.
- 返回
◆ getLastErrorString()
| QString DA::DATextReadWriter::getLastErrorString |
( |
| ) |
const |
◆ getReadOnceCharCount()
| int DA::DATextReadWriter::getReadOnceCharCount |
( |
| ) |
const |
总共读取的字符数,当读取到达此字符数后会发射readAllComplete
- 返回
- 返回-1代表没有设置,此时会读取所有到文件末尾才发射一次readComplete
◆ getReadOnceLineCount()
| int DA::DATextReadWriter::getReadOnceLineCount |
( |
| ) |
const |
一次读取的行数,当开始读取时达到这个行数后会发射readComplete, 继续往下读取(没有超过m_totalReadLineCount的行数),再次达到m_readOnceLineCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的行数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
- 返回
- 返回-1代表没有设置,此时会读取所有到文件末尾才发射一次readComplete
- 注解
- 默认为500
◆ getTotalReadCharCount()
| int DA::DATextReadWriter::getTotalReadCharCount |
( |
| ) |
const |
一次读取的字符数,当开始读取时达到这个字符数后会发射readComplete, 继续往下读取(没有超过m_totalReadCharCount的字符数),再次达到m_readOnceCharCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的字符数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
- 返回
- 返回-1代表没有设置
◆ getTotalReadLineCount()
| int DA::DATextReadWriter::getTotalReadLineCount |
( |
| ) |
const |
总共读取的行数,当读取到达此行后会发射readAllComplete
- 返回
- 返回-1代表没有设置,此时会一直度到文本末尾
◆ isOpen()
| bool DA::DATextReadWriter::isOpen |
( |
| ) |
const |
◆ open()
| bool DA::DATextReadWriter::open |
( |
QIODevice::OpenMode |
mode = QIODevice::ReadOnly | QIODevice::Text | ) |
|
◆ operatorFile
| void DA::DATextReadWriter::operatorFile |
( |
std::function< void(QFile *) > |
fun | ) |
|
|
slot |
传入一个操作QFile的函数指针,此函数指针用于操作内部保存的QFile
- 参数
-
◆ readComplete
| void DA::DATextReadWriter::readComplete |
( |
const QString & |
str, |
|
|
bool |
reachEnd |
|
) |
| |
|
signal |
完成一次读取会返回此信号
- 参数
-
| str | 读取的文字 |
| reachEnd | 是否到达最后,为true,说明全文读取完毕 |
◆ setReadOnceCharCount()
| void DA::DATextReadWriter::setReadOnceCharCount |
( |
int |
readOnceCharCount | ) |
|
设置总共读取的字符数,当读取到达此字符数后会发射readAllComplete
- 参数
-
| readOnceCharCount | -1代表没有设置,此时会读取所有到文件末尾才发射一次readComplete |
◆ setReadOnceLineCount()
| void DA::DATextReadWriter::setReadOnceLineCount |
( |
int |
readOnceLineCount | ) |
|
设置一次读取的行数,但开始读取时达到这个行数后会发射readComplete, 继续往下读取(没有超过m_totalReadLineCount的行数),再次达到m_readOnceLineCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的行数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
- 参数
-
| readOnceLineCount | -1代表没有设置,此时会读取所有到文件末尾才发射一次readComplete |
- 注解
- 默认为500
◆ setSkipHeader()
| void DA::DATextReadWriter::setSkipHeader |
( |
std::size_t |
v | ) |
|
◆ setStringFun()
| void DA::DATextReadWriter::setStringFun |
( |
const StringFun & |
fun | ) |
|
处理每次读取的函数指针,默认为nullptr
- 参数
-
◆ setTotalReadCharCount()
| void DA::DATextReadWriter::setTotalReadCharCount |
( |
int |
totalReadCharCount | ) |
|
设置一次读取的字符数,当开始读取时达到这个字符数后会发射readComplete, 继续往下读取(没有超过m_totalReadCharCount的字符数),再次达到m_readOnceCharCount设定值后发射readComplete, 继续往下读取,直到到达m_totalReadLineCount的字符数(发射readAllComplete)或文件的末尾(发射reachTextEnd和readAllComplete)
- 参数
-
◆ setTotalReadLineCount()
| void DA::DATextReadWriter::setTotalReadLineCount |
( |
int |
totalReadLineCount | ) |
|
设置总共读取的行数,当读取到达此行后会发射readAllComplete
- 参数
-
该类的文档由以下文件生成:
- /home/runner/work/data-workbench/data-workbench/src/DAUtils/DATextReadWriter.h
- /home/runner/work/data-workbench/data-workbench/src/DAUtils/DATextReadWriter.cpp