我是Qt的新人,我正在制作游戏。我想显示图标,但在放了一些代码后我无法在任何地方找到它。我很困惑因为我没有得到任何错误,所以我很确定我只是没有添加一些东西。帮助
Combat.h文件
#ifndef COMBAT
#define COMBAT
#include <QImage>
#include <QGraphicsPixmapItem>
class Combat: public QGraphicsPixmapItem{
public:
// constructors
//Combat(QPixmap *parent=NULL);
Combat(const QString x);
// setters/getters
void getOwner(QString x);
private:
QString owner;
};
Combat.cpp
#include "Combat.h"
#include <QGraphicsScene>
Combat::Combat(const QString x){
// draw graphics
setPixmap(QPixmap(x));
}
void Combat::getOwner(QString x){
owner = x;
}
#endif // COMBAT
Interface.h
#ifndef INTERFACE
#define INTERFACE
#include <QList>
#include "Hex.h"
#include "Combat.h"
class Interface{
public:
// constructors
Interface();
// getters/setters
QList<Hex*> getHexes();
void getOwner(int x);
// public methods
void placeHexes();
void placeCombat();
private:
void createHexColumn(int x, int y, int numOfRows);
QList<Hex*> hexes;
void createCombatIcon(int x, int y, QString z);
int owner;
};
#endif // INTERFACE
Interface.cpp
#include "Interface.h"
#include "Game.h"
extern Game* game;
Interface::Interface(){
}
QList<Hex *> Interface::getHexes(){
return hexes;
}
void Interface::placeHexes(){
createHexColumn(100,100,6);
}
void Interface::placeCombat()
{
createCombatIcon(100,100,":/grafika/atak_magiczny.png");
}
void Interface::createCombatIcon(int x, int y, QString z)
{
Combat* icon = new Combat(z);
icon->getOwner("player1");
icon->setPos(x,y);
game->scene->addItem(icon);
}
我不确定哪里缺少什么
答案 0 :(得分:0)
我通过在Qt Creator中将我的图形添加到资源文件来解决了这个问题......