i'm new qt , programming in general, , i'm having issues adding score game i'm making. have score class, obstacle class, , game class, among others, , i'm trying connect qtimer used spawn obstacles update score, score goes 1 every 2500 milliseconds. please help!
here's score header file:
#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
and here's score source file:
//i'm including qfont, qstring, qobject, , qdebug #include "score.h" #include "obstacle.h" score::score(qgraphicsitem *parent) : qgraphicstextitem(parent){ //initialize score 0 score_value = 0; //draw 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; }
and here's relevant portions of game class source file, creates whole game:
#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 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 timer connect(timer, signal(timeout()), score, slot(increase_score())); }
right errors
symbol(s) not found architecture x86_64
linker command failed exit code 1
i'm trying use signals , slots score updates instead of sitting @ zero...but have no idea how fix error. help!
the signals , slots mechanism depends on source code generated qt tool called moc. need run moc on score.h, , compile resulting c++ source in project. missing symbols in moc c++ code.
if use qmake generate project file you, after add new classes signals/slots need run qmake again.