找不到错误 QT
Can't find the error QT
我得到这个错误的所有设置函数错误:期望的主表达式在'。"令牌: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);
相关文章:
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- Qt 错误 iso c++ 禁止指针和整数之间的比较 -permissive
- Qt 错误消息"qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed"
- Qt 错误:未定义对"str2ba"的引用
- 为安卓构建时出现Qt错误
- 模型对话框移动到主窗口后面的Qt错误
- QT 5 [ 错误: QtGui/QApplication: 没有这样的文件或目录]
- QT错误:运行代码后,在QT中获得Protobuf错误
- Linux/QT-错误创建SSL上下文(错误:140A90C4 ..)
- Qt 错误:错误:调用"QHBoxLayout::addItem(QPushButton*&)"没有匹配函数
- QT错误:搜索不存在的函数
- QT错误:LNK1120:1未解决的外部Main.OBJ:-1:错误:LNK2019运行QMAKE
- 在QIODevice::Append模式下打开的QFile意外工作.这是一个Qt错误吗
- QT - C++错误:在此上下文中'QWidget::QWidget(const QWidget&)'是私有的
- Qt错误:在Mac OS X Yosemite上找不到体系结构x86_64的符号
- 在Mac中构建Qt 5.4错误
- 连接DLL后出现QT 5.4错误
- 带有 QT 错误的 OpenGL:ASSERT:"QOpenGLFunctions::isInitialized(d_ptr)" 。无法创建 OpenGL 上下文
- 在Qt Creator中编译时出现Qt错误
- 参数计数不匹配 SQLite 和 Qt 错误