简体   繁体   中英

Qt - No matching function for call to?

Call this from a QWidget: Parser->xmlParser(_layout, xmlPath, comingFrom, mapCount); , but get two "No matching function for call to..." errors.

No matching function for call to QMap<QMap<QString, QString>, int>::insert No matching function for call to 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 file:

<menu>
<item id="1"><something>title 1</something><somethin2>parent</something2></item>
<item id="2"><something>title 2</something><something2>locationofsomething</something2></item>
</menu>

I don't understand what you are doing exactly, but while inserting to a map, you have to specify both the key and the value. That is the reason for the first error you mentioned.

Also you have a mismatch in parameters, that is to say, you have a list of QMap (the mapList list), and you are trying to append QMap< QMap< QString, QString >, int > (the returnedList map). That's the reason for your second error.

You aren't passing the correct arguments to QMap::insert() and QList::append() :

  • QMap::insert() takes two parameters (a key and a value), but you are only passing one parameter.
  • mapList[mapCount] (by the way, mapCount is an out-of-range index here) is a QList that holds QMap<QString,QString> , but you are trying to append a QMap<QMap<QString,QString>,int> .

Also, the return type for parseItem() doesn't match in your .h and .cpp files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM