我收到一個錯誤,我不知道如何解決。
我創建了一個CustomScene繼承的類,QGraphicsScene我想覆寫這個類中的滑鼠功能。
我正在嘗試通過拖放在場景上創建一個矩形,甚至當我嘗試使用滑鼠event->pos().x()獲取滑鼠的位置時,我也獲得了QGraphicsSceneMouseEvent對不完整型別的成員訪問權限QGraphicsSceneMouseEvent
#ifndef CUSTOMSCENE_H
#define CUSTOMSCENE_H
#include <QGraphicsScene>
#include <customrectitem.h>
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit CustomScene(QObject *parent = nullptr);
QGraphicsScene* scene = new QGraphicsScene;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
};
#endif // CUSTOMSCENE_H
#include "customscene.h"
#include <QDebug>
CustomScene::CustomScene(QObject *parent)
: QGraphicsScene{parent}
{
}
void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "the scene know that the mouse is pressed";
QGraphicsRectItem* rect = new QGraphicsRectItem(event->pos().x(),event->pos.y(),100,100);
//the line of the error
this->addItem(rect);
}
void CustomScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "the scene know that the mouse is moving";
}
void CustomScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "the scene know that the mouse is released";
}
uj5u.com熱心網友回復:
當您嘗試使用僅使用前向宣告宣告的型別(即呼叫方法)時,通常會發生“對不完整型別的成員訪問” 。
在這種情況下,QGraphicsSceneMouseEvent在qgraphicsscene.h 中向前宣告。實際宣告在qgraphicssceneevent.h 中。使用它只是把
#include <QGraphicsSceneMouseEvent>
在你的來源。請注意,這也在檔案的第一段中明確說明。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/395703.html
標籤:C qt qgraphicsscene 不完全类型
