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>
ドキュメントに正確に従ったので、どこが間違っていたのかわかりません。たぶん私は不注意です。私の間違いを指摘するのを手伝ってください。ありがとう :)