c++ - Qt GUI C++ 全局声明错误
问题描述
我在添加全局变量时遇到问题。我尝试在一个单独的头文件中声明它们,称为“declare_struct.h”我将 .h 包含在 .cpp 中,但仍然无法引用变量,当我尝试在函数中使用它们时,我不断收到错误消息在头文件中。
这是标题中的内容:
#define DECLARE_STRUCT_H
#include <QString>
#include <QVector>
#include <QRegularExpression>
#include <QFile>
#include <QTextStream>
extern QString helper_quest, helper_a, helper_b, helper_c, helper_d, helper_good;
class Question
{
public:
Question();public:
QString quest, answer_a, answer_b, answer_c, answer_d, answer_good;
};
extern Question q;
extern QVector<Question> quiz;
void load (QString filename)
{
quiz.clear();
QRegularExpression re_Q("Q: ");
QRegularExpression re_A("A: ");
QRegularExpression re_B("B: ");
QRegularExpression re_C("C: ");
QRegularExpression re_D("D: ");
QRegularExpression re_Ans("Ans: ");
QString trash, need;
QFile inf(filename);
/// if (inf.good())
/// {
/// getline(inf, trash); ///deletes the title of the questionnaire
/// }
for (int i =0; i<10; i++)
{
QTextStream in(&inf);
q.quest = in.readLine();
q.quest.remove(re_Q);
q.answer_a = in.readLine();
q.answer_a.remove(re_A);
q.answer_b = in.readLine();
q.answer_b.remove(re_B);
q.answer_c = in.readLine();
q.answer_c.remove(re_C);
q.answer_d = in.readLine();
q.answer_d.remove(re_D);
q.answer_good = in.readLine();
q.answer_good.remove(re_Ans);
quiz.push_back(q);
}
}
#endif // DECLARE_STRUCT_H ```
in the declare_struct.cpp :
``` #include "declare_struct.h"
Question::Question()
{
}
```
And I keep getting the following errors:
[errors][1]
[1]: https://i.stack.imgur.com/ZyerL.png
解决方案
推荐阅读
- javascript - 如何让 javascript 在我的 HTML 页面上编写消息?
- google-tag-manager - VideoJS nteraction 不会触发谷歌标签管理器
- c# - C# & MongoDB.Driver - 为什么我找不到文档提到的异步方法?
- log4j2 - Log4j2:我可以通过配置更改记录事件的日志级别吗?
- r - 使用 rpy2 将 NULL 从 Python 转换为 R
- c# - 如何提高 ML.Net 中不同机器学习算法的预测精度
- html - 如何创建网页
- java - 在重新启动 Hazelcast 最旧的节点时,它不会加入集群
- javascript - 从数据库读取值时更改文本背景颜色
- c# - 在另一个 IList 数据模型中存储 Array 或 IList