Вызовите это из QWidget: Parser->xmlParser(_layout, xmlPath, comingFrom, mapCount);
, но получите две ошибки «Нет подходящей функции для вызова ...».
Нет соответствующей функции для вызова QMap<QMap<QString, QString>, int>::insert
Нет соответствующей функции для вызова QList<QMap<QString, QString>>::append
parser.cpp
#include "parser.h"
Parser::Parser() {
}
void Parser::xmlParser(QVBoxLayout* _layout, QString xmlPath, QString comingFrom, int mapCount) {
QFile* file = new QFile(xmlPath);
if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
}
QXmlStreamReader xml(file);
QMap< QMap< QString, QString >, int > returnedList;
QList< QMap<QString,QString> > * mapPointer;
QList< QMap<QString,QString> > mapList[mapCount];
mapPointer = mapList;
int count = 0;
while(!xml.atEnd() && !xml.hasError()) {
QXmlStreamReader::TokenType token = xml.readNext();
if(token == QXmlStreamReader::StartDocument) {
continue;
}
if(token == QXmlStreamReader::StartElement) {
if(xml.name() == "menu") {
continue;
}
if(xml.name() == "item") {
if (comingFrom == "suchandsuch") {
//errors get thrown like crazy here
**returnedList.insert(this->parseItem(xml, _layout, count));
mapList[mapCount].append(returnedList);
returnedList.empty();**
}
//iterate through mapList and do stuff
}
}
}
if(xml.hasError()) {
}
xml.clear();
}
QList< QMap<QString, QString>, int > Parser::parseItem(QXmlStreamReader& xml, QVBoxLayout* _layout, int count) {
QList<QMap<QString, QString>, int> returnedList;
QMap<QString, QString> mapMenu;
QString keyName;
QString valueName;
if(xml.tokenType() != QXmlStreamReader::StartElement && xml.name() == "item") {
return mapMenu;
}
QXmlStreamAttributes attributes = xml.attributes();
if(attributes.hasAttribute("id")) {
mapMenu["id"] = attributes.value("id").toString();
}
xml.readNext();
while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "item")) {
if(xml.tokenType() == QXmlStreamReader::StartElement) {
if(xml.name() == "something") {
count++;
keyName = xml.name().toString();
xml.readNext();
valueName = xml.text().toString();
mapMenu.insert(mapMenu["id"], valueName);
returnedList.append(mapMenu, count);
}
}
xml.readNext();
}
return returnedList;
}
parser.h
#ifndef PARSER_H
#define PARSER_H
#include <QtGui/QMainWindow>
#include <QtGui/QScrollArea>
#include <QtGui/QFrame>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QGroupBox>
#include <QtGui/QFormLayout>
#include <QtGui/QMessageBox>
#include <QtCore/QPointer>
#include <QtCore/QFile>
#include <QtCore/QIODevice>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtXml/QXmlStreamReader>
#include <QtDebug>
#include <QBool>
#include <QSignalMapper>
class Parser {
public:
Parser();
void xmlParser(QVBoxLayout* _layout, QString xmlPath, QString comingFrom, int mapCount);
QMap < QMap< QString, QString >, int > parseItem(QXmlStreamReader& xml, QVBoxLayout* _layout, int count);
private:
QPointer<QVBoxLayout> _layout;
QString xmlPath;
QString comingFrom;
};
#endif // PARSER_H
XML-файл:
<menu>
<item id="1"><something>title 1</something><somethin2>parent</something2></item>
<item id="2"><something>title 2</something><something2>locationofsomething</something2></item>
</menu>