c++ – Qt XML Input – Education Career Blog

I’m trying to input data from an XML file in a C++ program using the Qt tool kit. My XML data is formatted as follows:

    <other_info>other info<\other_info>
    <last_modified>Mar 28 2009 8:16 pm<\last_modified>

Currently the function that I have to read in the XML is as follows. Unfortunately it recognizes the data from the first tag (the title) and then returns all future attempts to access the data as NULL. The subRoot that I pass in is the domDocument.documentElement(). I am brand new to XML and somewhat new to Qt, and would appreciate any help you could offer in solving my problem! Thank you very much.

void XmlHandler::readXML(QStandardItemModel *model, QDomNode subRoot){
  QDomElement node;
  QString title;
  int row;
  QString parent;
  QString description;
  QString other_info;
  QString location;
  QString last_modified;
  QString radio;
  QString value;
  bool flag;

  if (subRoot.isNull())
    return; // error condition

  for (int i = 0; i < N_STRINGS; i++){
    node = subRoot.firstChildElement(tagNamei); // returns NULL all but the 1st time
    value = DEFAULT_VALUE;

    value = node.text();
    switch (i) {
      case 0:
      title = value;
      case 1:
      row = value.toInt();
      case 2:
      parent = value;
      case 3:
      description = value;
      case 4:
      other_info = value;
      case 5:
      location = value;
      case 6:
      last_modified = value;
      case 7:
          radio = value;


Your XML data is not valid XML – the backslashes should be forward slashes. For example:


should be:


Leave a Comment