내가 'GraphicsPixmapItem *'호환되지 않는 유형에서 'GraphicsPixmapItem *'컴파일러 오류에 "할당을 반환하는 다음과 같은 코드가 있습니다.호환되지 않는 유형
누군가가 나를 도울 수 있습니까? 여기
코드입니다 :주요 파일 :
#include "graphicsscene.h"
#include <QApplication>
#include <QGraphicsView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GraphicsScene scene;
scene.setSceneRect(0, 0, 318, 458);
QGraphicsView view(&scene);
view.setBackgroundBrush(QPixmap(":/images/background.jpg"));
view.show();
return a.exec();
}
사용자 정의 GraphicsScene 헤더 :
,536#ifndef GRAPHICSSCENE_H
#define GRAPHICSSCENE_H
#include <QGraphicsScene>
#include "graphicspixmapitem.h"
class GraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit GraphicsScene(QWidget *parent = 0);
QGraphicsPixmapItem *Logo;
};
#endif // GRAPHICSSCENE_H
사용자 정의 GraphicsScene의 CPP :
#include "graphicsscene.h"
GraphicsScene::GraphicsScene(QWidget *parent) :
QGraphicsScene()
{
QPixmap Contactinfo(":/images/ScreenContacts.png");
GraphicsPixmapItem *buf = new GraphicsPixmapItem;
buf = addPixmap(Contactinfo);
buf->setPos(0, 40);
buf->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsScenePositionChanges);
}
사용자 정의 QGraphicsPixmapItem 헤더 :
#ifndef GRAPHICSPIXMAPITEM_H
#define GRAPHICSPIXMAPITEM_H
#include <QObject>
#include <QGraphicsPixmapItem>
class GraphicsPixmapItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
GraphicsPixmapItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
#endif // GRAPHICSPIXMAPITEM_H
마지막으로 사용자 정의 QGraphicsPixmapItem의 CPP :
#include "graphicspixmapitem.h"
GraphicsPixmapItem::GraphicsPixmapItem(QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsPixmapItem(parent, scene)
{
}
#include <QDebug>
QVariant GraphicsPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
qDebug() << "itemChange Triggered";
if (change == ItemPositionChange) {
qDebug() << "Position changed";
}
return QGraphicsItem::itemChange(change, value);
}