Handling Document Formats: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Add "cleanup" tag)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
[[Category:Developing_with_Qt]]
[[Category:Developing_with_Qt]]
[toc align_right="yes" depth="3"]
[toc align_right="yes" depth="3"]

Revision as of 15:43, 3 March 2015

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

[toc align_right="yes" depth="3"]

Handling Document Formats

There are many use-cases that may require Qt applications to deal with document formats - usually either involving transparently parsing/writing documents, or displaying documents to the user. This page covers some general considerations, and provides an overview of wiki pages discussing available options for specific formats.

General Considerations

The Scribe Framework

While not being able to provide built-in functionality for every imaginable document handling use-case, Qt does ship with a generic "rich text document framework":/doc/qt-4.8/richtext.html, nicknamed "Scribe".

[[Image:{float:right;margin:0 1em 1em 1em}/doc/qt-4.8/images/richtext-examples.png|]] It revolves around the class "QTextDocument":/doc/qt-5/QTextDocument.html, which provides an "object-oriented frame-based representation":/doc/qt-4.8/richtext-structure.html of a document consisting of blocks (sub-frames, paragraphs, tables, lists, …) which in turn can contain strings of styled text fragments. API is included for loading from HTML and saving to HTML and ODT (see "QTextDocumentWriter":/doc/qt-5/QTextDocumentWriter.html), as well as for displaying documents to the user (in read-only or interactively editable mode) through "QTextEdit":/doc/qt-5/QTextEdit.html .

The Scribe framework's built-in document feature set (which all built-in loading/saving/displaying/editing operations are limited to) covers only the basics and doesn't come anywhere close to what modern full-featured document formats and authoring tools (like Microsoft Word) support, although it is sufficient for many tasks such as generating reports. Most parts of the framework are extensible through subclassing, so application authors can implement additional document features or save/load formats as they see fit.

XML Processing

Many modern document formats are based on XML. So depending on what kind of processing you wish to perform, manual parsing/writing using "Qt's powerful XML handling classes":/doc/qt-4.8/xml-processing.html might be a viable option.

  • The efficient "XML Streaming classes":/doc/qt-4.8/xml-streaming.html available in QtCore are recommended for most purposes.
  • In some cases the SAX and DOM classes from the "QtXml module":/doc/qt-4.8/qtxml.html can be a useful alternative.
  • If your application needs to repeatedly extract a certain piece of information, or apply a certain transformation, on many documents with a similar structure, then the "QtXmlPatterns module":/doc/qt-4.8/qtxmlpatterns.html might provide an elegant solution.

Individual Formats

For information/tips (gathered by the community) on how to work with a specific document format in your Qt application, click on the name of the format in the list below:

Text Documents

table{width:95%;margin-left:2.5%}. |{width:18em}. HTML |{width:12em}. {color:#567;font-family:monospace}.html .htm .xhtml | | |{width:18em}. PDF |{width:12em}. {color:#567;font-family:monospace}.pdf | | |{width:18em}. Microsoft Word |{width:12em}. {color:#567;font-family:monospace}.doc .docx | (native format of Microsoft Word) | |{width:18em}. OpenDocument Text |{width:12em}. {color:#567;font-family:monospace}.odt | (native format of OpenOffice/LibreOffice Writer, among others) | |{width:18em}. Rich Text Format |{width:12em}. {color:#567;font-family:monospace}.rtf | (here referring specifically to Microsoft's "RTF" format, not rich text in general) | |{width:18em}. LaTeX |{width:12em}. {color:#567;font-family:monospace}.tex | |

Spreadsheets

table{width:95%;margin-left:2.5%}. |{width:18em}. Microsoft Excel |{width:12em}. {color:#567;font-family:monospace}.xls, .xlsx | (native format of Microsoft Excel) | |{width:18em}. OpenDocument Spreadsheet |{width:12em}. {color:#567;font-family:monospace}.ods | (native format of OpenOffice/LibreOffice Calc, among others) | |{width:18em}. comma-separated values |{width:12em}. {color:#567;font-family:monospace}.csv | (simple file format that is widely supported by consumer, business, and scientific applications.) |

Presentations

table{width:95%;margin-left:2.5%}. |{width:18em}. Microsoft Powerpoint |{width:12em}. {color:#567;font-family:monospace}.ppt, .pptx | (native format of Microsoft Powerpoint) | |{width:18em}. OpenDocument Presentation |{width:12em}. {color:#567;font-family:monospace}.odp | (native format of OpenOffice/LibreOffice Impress, among others) |

Math/Formulae

table{width:95%;margin-left:2.5%}. |{width:18em}. MathML |{width:12em}. {color:#567;font-family:monospace}.mml | | |{width:18em}. OpenDocument Formula |{width:12em}. {color:#567;font-family:monospace}.odf | (native format of OpenOffice/LibreOffice Math, among others) | |{width:18em}. LaTeX Math | | |

p{color:#fff;border-bottom:solid 1px #ccc}. .

See Also