我想借助 Q_D 宏在派生类中使用 d 指针。
这是我的父类:
class DIGIKAM_EXPORT GraphicsDImgView : public QGraphicsView
{
Q_OBJECT
public:
class GraphicsDImgViewPrivate;
protected:
GraphicsDImgViewPrivate* const d_ptr;
protected:
Q_DECLARE_PRIVATE(GraphicsDImgView)
};
和我的 GraphicsDImgViewPrivate 类:
class GraphicsDImgView::GraphicsDImgViewPrivate
{
public:
GraphicsDImgViewPrivate()
{
scene = 0;
item = 0;
layout = 0;
cornerButton = 0;
panIconPopup = 0;
movingInProgress = false;
showText = true;
}
QGraphicsScene* scene;
GraphicsDImgItem* item;
SinglePhotoPreviewLayout* layout;
QToolButton* cornerButton;
KPopupFrame* panIconPopup;
QPoint mousePressPos;
QPoint panningScrollPos;
bool movingInProgress;
bool showText;
};
GraphicsDImgView::GraphicsDImgView(QWidget* const parent)
: QGraphicsView(parent), d_ptr(new GraphicsDImgViewPrivate)
{
Q_D(GraphicsDImgView);
d->scene = new QGraphicsScene(this);
d->scene->setItemIndexMethod(QGraphicsScene::NoIndex);
setScene(d->scene);
d->layout = new SinglePhotoPreviewLayout(this);
d->layout->setGraphicsView(this);
}
在派生类中,我编写了一个方法,我想在其中使用 GraphicsDImgView 的 d 指针:
bool ImageRegionWidget::movingInProgress()
{
Q_D(GraphicsDImgView);
return d->movingInProgress;
}
但是构建给了我以下错误消息
在成员函数'bool Digikam::ImageRegionWidget::movingInProgress()':...path....错误:无效使用不完整类型'class GraphicsDImgView::GraphicsDImgViewPrivate'</p>
和
graphicsdimgview.h:128:11:错误:'class GraphicsDImgView::GraphicsDImgViewPrivate'的前向声明</p>
我完全按照文档进行了操作,所以我不知道我哪里出错了。也许是我不小心。请帮我指出我的错误。谢谢 :)