我想在Q_D宏的帮助下使用派生类中的d指针。在qt私有类中使用的不完整类型无效
这里是我的父类:
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);
}
,并在派生类我写了一个方法,我想使用d指针GraphicsDmgView:
bool ImageRegionWidget::movingInProgress()
{
Q_D(GraphicsDImgView);
return d->movingInProgress;
}
Howev呃构建给了我以下错误消息
In member function ‘bool Digikam::ImageRegionWidget::movingInProgress()’:...path.... error: invalid use of incomplete type ‘class GraphicsDImgView::GraphicsDImgViewPrivate’
和
graphicsdimgview.h:128:11: error: forward declaration of ‘class GraphicsDImgView::GraphicsDImgViewPrivate’
我严格遵循的文档,所以我不知道我在哪里出了错。也许我正在粗心大意。请帮我指出我的错误。谢谢:)
快,让完整的代码。看起来你在声明'GraphicsDImgViewPrivate'和include的顺序时有错误。另外...什么是你的“属性”? –
对不起,我会纠正他们... – wceo