Skip to content

Commit

Permalink
Doc: Add Qt6 XML porting guide
Browse files Browse the repository at this point in the history
Fixes: QTBUG-88026
Change-Id: I5f23e3ba984b7aaa326b713a03101797298c44d7
Reviewed-by: Mårten Nordheim <[email protected]>
Reviewed-by: Sona Kurazyan <[email protected]>
  • Loading branch information
kaheimri committed Nov 10, 2020
1 parent ee02576 commit 059ca16
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion src/xml/doc/src/qt6-changes.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,76 @@
In this topic we summarize those changes in Qt XML, and provide
guidance to handle them.

\section1 ADD STUFF HERE
\section1 Simple API for XML (SAX) parser

\section2 QXmlStreamReader

In Qt6, all \c SAX classes have been removed from Qt XML, please use
QXmlStreamReader for reading XML files. Here are some simple steps to
port your current code to QXmlStreamReader:

\oldcode
QFile *file = new QFile(...);
QXmlInputSource *source = new QXmlInputSource(file);

Handler *handler = new Handler;

QXmlSimpleReader xmlReader;
xmlReader.setErrorHandler(handler);
xmlReader.setContentHandler(handler);

if (xmlReader.parse(source)) {
... // do processing
} else {
... // do error handling
}
\newcode
QFile file = ...;
QXmlStreamReader reader(&file);

while (!reader.atEnd()) {
reader.readNext();
... // do processing
}
if (reader.hasError()) {
... // do error handling
}
\endcode

\section2 QDom and QDomDocument

In Qt6, \c SAX classes have been removed and therefore QDomDocument
cannot use them anymore. That's why it has been re-implemented using
the QXmlStreamReader. This brings a few behavioral changes:

\list
\li Attribute values will be normalized. For example
\c{<tag attr=" a \n b " />} will be equivalent to \c{<tag attr="a b"/>}.
\li Identical qualified attribute names won't be allowed anymore, i.e.
attributes of an element must have unique names.
\li Undeclared namespace prefixes won't be allowed anymore.
\endlist

If you are using QDomDocument and relying on any of these, please update
your code and XML documents accordingly.

\section2 Qt Core5 compatibility library

If your application or library cannot be ported right now, the \l
QXmlSimpleReader and related classes do still exist in Qt5Compat to keep
old code-bases working. If you want to use those SAX classes further, you
need to link against the new Qt5Compat module and add this line to your \l
qmake \c .pro file:

\code
QT += core5compat
\endcode

In case you already ported your application or library to the
\l {Build with CMake}{cmake} build system, add the following to your
\c CMakeList.txt:
\code
PUBLIC_LIBRARIES
Qt::Core5Compat
\endcode
*/

0 comments on commit 059ca16

Please sign in to comment.