QTextDocumentWriter 类提供格式无关接口,用于写入 QTextDocument 到文件或其它设备。 更多...
头: | #include <QTextDocumentWriter> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
QTextDocumentWriter () | |
QTextDocumentWriter (QIODevice * device , const QByteArray & format ) | |
QTextDocumentWriter (const QString & fileName , const QByteArray & format = QByteArray()) | |
~QTextDocumentWriter () | |
QIODevice * | device () const |
QString | fileName () const |
QByteArray | format () const |
void | setDevice (QIODevice * device ) |
void | setFileName (const QString & fileName ) |
void | setFormat (const QByteArray & format ) |
bool | write (const QTextDocument * document ) |
bool | write (const QTextDocumentFragment & fragment ) |
QList<QByteArray> | supportedDocumentFormats () |
To write a document, construct a QTextDocumentWriter object with either a file name or a device object, and specify the document format to be written. You can construct a writer and set the format using setFormat () later.
调用
write
() to write the document to the device. If the document is successfully written, this function returns
true
. However, if an error occurs when writing the document, it will return false.
调用 supportedDocumentFormats () for a list of formats that QTextDocumentWriter can write.
Since the capabilities of the supported output formats vary considerably, the writer simply outputs the appropriate subset of objects for each format. This typically includes the formatted text and images contained in a document.
Constructs an empty QTextDocumentWriter object. Before writing, you must call setFormat () to set a document format, then setDevice () 或 setFileName ().
Constructs a QTextDocumentWriter object to write to the given device in the document format specified by format .
[explicit]
QTextDocumentWriter::
QTextDocumentWriter
(const
QString
&
fileName
, const
QByteArray
&
format
= QByteArray())
Constructs an QTextDocumentWriter object that will write to a file with the name fileName , using the document format specified by format 。若 format is not provided, QTextDocumentWriter will detect the document format by inspecting the extension of fileName .
销毁 QTextDocumentWriter 对象。
Returns the device currently assigned, or
nullptr
若没有设备被赋值。
另请参阅 setDevice ().
若目前赋值设备是 QFile ,或者若 setFileName () has been called, this function returns the name of the file to be written to. In all other cases, it returns an empty string.
另请参阅 setFileName () 和 setDevice ().
返回用于写文档的格式。
另请参阅 setFormat ().
Sets the writer's device to the device specified. If a device has already been set, the old device is removed but otherwise left unchanged.
若设备尚未打开, QTextDocumentWriter will attempt to open the device in WriteOnly mode by calling open().
注意: This will not work for certain devices, such as QProcess , QTcpSocket and QUdpSocket , where some configuration is required before the device can be opened.
另请参阅 device () 和 setFileName ().
Sets the name of the file to be written to fileName . Internally, QTextDocumentWriter 将创建 QFile and open it in WriteOnly mode, and use this file when writing the document.
另请参阅 fileName () 和 setDevice ().
Sets the format used to write documents to the format 指定。 format is a case insensitive text string. For example:
QTextDocumentWriter writer; writer.setFormat("odf"); // same as writer.setFormat("ODF");
可以调用 supportedDocumentFormats () 了解完整格式列表 QTextDocumentWriter 支持。
另请参阅 format ().
[static]
QList
<
QByteArray
> QTextDocumentWriter::
supportedDocumentFormats
()
返回文档格式列表支持通过 QTextDocumentWriter .
默认情况下,Qt 可以写入下列格式:
格式 | 描述 |
---|---|
plaintext | 纯文本 |
HTML | HTML (超文本标记语言) |
markdown | Markdown (CommonMark 或 GitHub 方言) |
ODF | ODF (开放文档格式) |
另请参阅 setFormat ().
写入给定
document
到赋值设备 (或文件) 并返回
true
若成功;否则返回
false
.
Writes the document fragment specified by
fragment
到赋值设备 (或文件) 并返回
true
若成功;否则返回
false
.