2013-05-20 2 views
0

내가 '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); 
} 

답변

1

QGraphicsScene :: addPixmap() QGraphicsPixmapItem을 반환합니다. 다른 유형 인 GraphicsPixmapItem에 대한 포인터에 QGraphicsPixmapItem에 대한 포인터를 지정하려고합니다.

또한 버피에 할당하여 새로운 사용하고 다음 두 가지 객체 (new에서), 즉 하나의 GraphicsPixmapItem 및 항목 (addPixmap)에서 하나 QGraphicsPixmap를 만드는, QGraphicsScene::addPixmap()를 호출 있습니다.

buf->setPixmap(Contactinfo);과 같은 것이 좋으며 장면 생성자에서 addItem(buf);을 호출하고 addPixmap() 호출을 제거하십시오.