找不到错误 QT

Can't find the error QT

本文关键字:QT 错误 找不到      更新时间:2023-10-16

我得到这个错误的所有设置函数错误:期望的主表达式在'。"令牌:All.push_back (Country.setName(国家[0]));^

这是repository.cpp

#include "repository.h"
#include <QFile>
#include <QTextStream>

void Repository::PopulateList()
{
    QFile file(":/countries.txt");
    if(file.open(QIODevice::ReadOnly))
    {
        QTextStream str(&file);
        while (!str.atEnd())
        {
            QString line = str.readLine();
            QStringList country = line.split(" ");
            All.push_back(Country.setName(country[0]));
            All.push_back(Country.setArtist(country[1]));
            All.push_back(Country.setSong(country[2]));
            All.push_back(Country.setScore(0));
        }
    }
    file.close();
}

this is repository.h

#ifndef REPOSITORY_H
#define REPOSITORY_H
#include <country.h>
#include <QString>
#include <vector>
class Repository
{
    private:
        std::vector<Country> All;
        void PopulateList();
    public:
        Repository();
        std::vector<Country> getAll(){return this->All;}
};
#endif // REPOSITORY_H

我做错了什么?

如果你想添加"Country"对象到你的列表,你需要声明一个,设置你的值,然后添加到你的列表:

QString line = str.readLine();
QStringList country = line.split(" ");
Country myCountry;
myCountry.setName(country[0]);
myCountry.setArtist(country[1]);
myCountry.setSong(country[2]);
myCountry.setScore(0);
All.push_back(myCountry);