Processing XML data using the QDomDocument class
Qt allows multiple ways to parse XML data, including the common method that we have covered in the previous examples. This time around, we're going to learn how to read data from an XML file using another class, called QDomDocument
.
How to do it…
Processing XML data using the QDomDocument
class is really simple:
First of all, we need to add the XML module to our project by opening the project (
.pro
) file and add the textxml
at the back ofcore
andgui
, like so:QT += core gui xml
Then, just like what we did in the first example in this chapter, create a user interface that carries a button that says Load XML:
After that, right-click on the button, choose Go to slot…, and select the
clicked()
option. Press the OK button and Qt will add a slot function to your source code.Go to
mainwindow.h
and add the following headers so that we can make use of these classes:#include <QDomDocument> #include <QDebug> #include <QFile> #include...