gpt4 book ai didi

c++ - Qt - 没有匹配的调用函数?

转载 作者:行者123 更新时间:2023-11-28 08:25:31 24 4
gpt4 key购买 nike

从 QWidget 中调用:Parser->xmlParser(_layout, xmlPath, comingFrom, mapCount); ,但得到两个“没有匹配的函数来调用...”错误。

没有匹配函数来调用 QMap<QMap<QString, QString>, int>::insert没有匹配函数来调用 QList<QMap<QString, QString>>::append

解析器.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;

}

解析器.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>

最佳答案

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

还有你的参数不匹配,也就是说,你有一个QMap列表(mapList列表),你试图附加QMap< QMap< QString, QString >, int >(returnedList map) .这就是你第二个错误的原因。

关于c++ - Qt - 没有匹配的调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4198952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com