QIODeviceBase Class
QIODevice 的基类,用于提供描述设备打开模式的标志。更多内容...
| 头文件: | #include <QIODevice> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 被继承者: |
公共类型
| flags | OpenMode |
| enum | OpenModeFlag { NotOpen, ReadOnly, WriteOnly, ReadWrite, Append, …, ExistingOnly } |
受保护函数
成员类型文档
enum QIODeviceBase::OpenModeFlag
flags QIODeviceBase::OpenMode
该枚举与QIODevice::open() 一起使用,用于描述设备被打开时的模式。它也是QIODevice::openMode() 函数返回的值。
| 常量 | 值 | 描述 |
|---|---|---|
QIODeviceBase::NotOpen | 0x0000 | 设备未打开。 |
QIODeviceBase::ReadOnly | 0x0001 | 设备处于读取打开状态。 |
QIODeviceBase::WriteOnly | 0x0002 | 设备已打开,可供写入。请注意,对于文件系统子类(例如QFile ),除非与 ReadOnly、Append 或 NewOnly 结合使用,否则此模式意味着截断。 |
QIODeviceBase::ReadWrite | ReadOnly | WriteOnly | 该设备以读写模式打开。 |
QIODeviceBase::Append | 0x0004 | 设备以追加模式打开,因此所有数据都写入文件的末尾。 |
QIODeviceBase::Truncate | 0x0008 | 如果可能,设备在打开之前会被截断。设备中所有先前的内容都会丢失。 |
QIODeviceBase::Text | 0x0010 | 读取时,行尾分隔符将转换为“\n ”。写入时,行尾分隔符将转换为本地编码,例如 Win32 中的“\r\n ”。 |
QIODeviceBase::Unbuffered | 0x0020 | 设备中的任何缓冲区都会被绕过。 |
QIODeviceBase::NewOnly | 0x0040 | 如果要打开的文件已经存在,则操作失败。仅当文件不存在时才创建并打开该文件。操作系统保证只有您才能创建并打开该文件。 请注意,此模式隐含 WriteOnly 标志,且允许与 ReadWrite 结合使用。该标志目前仅影响QFile 。未来其他类可能会使用此标志,但在那之前,若在QFile 以外的任何类中使用此标志,可能会导致未定义的行为。(自 Qt 5.11 起) |
QIODeviceBase::ExistingOnly | 0x0080 | 如果要打开的文件不存在,则操作失败。此标志必须与 ReadOnly、WriteOnly 或 ReadWrite 一起指定。 请注意,仅与 ReadOnly 标志一起使用此标志是多余的,因为当文件不存在时,ReadOnly 本身就会失败。此标志目前仅影响QFile 。未来其他类可能会使用此标志,但在那之前,若将其与QFile 以外的任何类一起使用,可能会导致未定义的行为。(自 Qt 5.11 起) |
某些标志(例如Unbuffered 和Truncate )在与某些子类一起使用时没有意义。 其中部分限制由子类所代表的设备类型所隐含。在其他情况下,限制可能源于实现本身,也可能由底层平台所强制;例如,QTcpSocket 不支持Unbuffered 模式,而本机API的限制导致QFile 在Windows上无法支持Unbuffered 。
OpenMode 类型是QFlags<OpenModeFlag> 的 typedef。它存储 OpenModeFlag 值的按“或”运算组合。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.