Qt - 呼叫没有匹配功能?

时间:2010-11-16 21:05:21

标签: c++ qt qt4

从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>

2 个答案:

答案 0 :(得分:1)

我不明白你在做什么,但是在插入地图时,你必须同时指定键和值。这就是你提到的第一个错误的原因。

你的参数也不匹配,也就是说,你有一个QMap列表(mapList列表),你试图追加QMap&lt; QMAP&LT; QString,QString&gt;,int&gt; (returnedList地图)。这就是你第二次错误的原因。

答案 1 :(得分:0)

您没有将正确的参数传递给QMap::insert()QList::append()

  • QMap::insert()有两个参数(一个键和一个值),但你只传递一个参数。
  • mapList[mapCount](顺便说一句,mapCount是一个超出范围的索引)是一个包含QMap<QString,QString>的QList,但是你试图追加QMap<QMap<QString,QString>,int>

此外,parseItem()的返回类型与.h和.cpp文件不匹配。