Qt:在架构x86_64找不到的符号

Qt: symbol(s) for not found for architecture x86_64

本文关键字:找不到 符号 x86 Qt      更新时间:2023-10-16

我是Qt的新手,只是一般的编程新手,我在为我正在制作的游戏添加分数时遇到了一些问题。我有一个分数类、障碍类和一个游戏类等,我正在尝试连接当前用于生成障碍物的 QTimer 来更新分数,以便分数每 2500 毫秒上升 1 个。请帮忙!

这是我的分数头文件:

#include <QGraphicsTextItem>
#include <QObject>
class score : public QGraphicsTextItem {
Q_OBJECT
public:
//constructor
score(QGraphicsItem * parent=0);
//other functions
int get_score();
int score_value;
public slots:
void increase_score();
};
#endif // SCORE

这是分数源文件:

//i'm including QFont, QString, QObject, and QDebug
#include "score.h"
#include "obstacle.h"
score::score(QGraphicsItem *parent) : QGraphicsTextItem(parent){
  //initialize score to zero
  score_value = 0;
  //draw the text
  setPlainText(QString("Score: ") + QString::number(score_value));
  setDefaultTextColor(Qt::white);
  setFont(QFont("arial",25));
}
void score::increase_score(){
  score_value++;
  qDebug() << "score has increased";
  setPlainText(QString("Score: ") + QString::number(score_value));
}
int score::get_score() {
 return score_value;
}

这是我的游戏类源文件的相关部分,它创建了整个游戏:

#include "game.h"
#include "score.h"
#include "main_menu.h"
#include "game_over.h"
#include <QObject>
#include <QImage>
#include <QBrush>
#include <QTimer>
game::game(QWidget *parent) {
...
  //create the score
  Score = new score();
  scene->addItem(Score);
  //spawn obstacles
  QTimer * timer = new QTimer();
  QObject::connect(timer, SIGNAL(timeout()), copter, SLOT(spawn()));
  timer->start(2500);
  //connect score to timer
  connect(timer, SIGNAL(timeout()), Score, SLOT(increase_score()));
  }

现在我收到错误说

找不到建筑x86_64符号

链接器命令失败,退出代码为 1

我正在尝试使用信号和插槽,以便分数更新,而不仅仅是坐在零......但我不知道如何解决此错误。感谢您的帮助!

信号和时隙机制依赖于名为MOC的Qt工具生成的额外源代码。您需要在 score.h 上运行 MOC,并在项目中编译生成的C++源。缺少的符号将位于 MOC C++代码中。

如果你使用 qmake 生成你的项目文件,它会为你完成所有这些工作,但是在你添加带有信号/插槽的新类后,你需要再次运行 qmake。