Hi,
I get the same compilation error with my classes, even though I have implemented the copy constructor. Here is the compiler output:
[ 16%] Building CXX object CMakeFiles/test2.dir/AbstractInteractiveQGraphicsItem.cpp.o
[ 33%] Building CXX object CMakeFiles/test2.dir/InteractiveQGraphicsLineItemData.cpp.o
[ 50%] Building CXX object CMakeFiles/test2.dir/InteractiveQGraphicsLineItem.cpp.o
[ 66%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
In
file included from
/usr
/include
/qt4
/QtCore
/QSharedData:1,
from InteractiveQGraphicsLineItem.h:23,
from main.cpp:2:
/usr/include/qt4/QtCore/qshareddata.h: In copy constructor 'QSharedDataPointer<T>::QSharedDataPointer(const QSharedDataPointer<T>&) [with T = InteractiveQGraphicsLineItemData]':
InteractiveQGraphicsLineItem.h:44: instantiated from here
/usr/include/qt4/QtCore/qshareddata.h:93: error: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: error: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h: In destructor 'QSharedDataPointer<T>::~QSharedDataPointer() [with T = InteractiveQGraphicsLineItemData]':
InteractiveQGraphicsLineItem.h:44: instantiated from here
/usr/include/qt4/QtCore/qshareddata.h:90: error: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: error: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h:90: warning: possible problem detected in invocation of delete operator:
/usr/include/qt4/QtCore/qshareddata.h:90: warning: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: warning: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h:90: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
make[2]: *** [CMakeFiles/test2.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/test2.dir/all] Error 2
make: *** [all] Error 2
[ 16%] Building CXX object CMakeFiles/test2.dir/AbstractInteractiveQGraphicsItem.cpp.o
[ 33%] Building CXX object CMakeFiles/test2.dir/InteractiveQGraphicsLineItemData.cpp.o
[ 50%] Building CXX object CMakeFiles/test2.dir/InteractiveQGraphicsLineItem.cpp.o
[ 66%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
In file included from /usr/include/qt4/QtCore/QSharedData:1,
from InteractiveQGraphicsLineItem.h:23,
from main.cpp:2:
/usr/include/qt4/QtCore/qshareddata.h: In copy constructor 'QSharedDataPointer<T>::QSharedDataPointer(const QSharedDataPointer<T>&) [with T = InteractiveQGraphicsLineItemData]':
InteractiveQGraphicsLineItem.h:44: instantiated from here
/usr/include/qt4/QtCore/qshareddata.h:93: error: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: error: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h: In destructor 'QSharedDataPointer<T>::~QSharedDataPointer() [with T = InteractiveQGraphicsLineItemData]':
InteractiveQGraphicsLineItem.h:44: instantiated from here
/usr/include/qt4/QtCore/qshareddata.h:90: error: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: error: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h:90: warning: possible problem detected in invocation of delete operator:
/usr/include/qt4/QtCore/qshareddata.h:90: warning: invalid use of incomplete type 'struct InteractiveQGraphicsLineItemData'
InteractiveQGraphicsLineItem.h:38: warning: forward declaration of 'struct InteractiveQGraphicsLineItemData'
/usr/include/qt4/QtCore/qshareddata.h:90: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
make[2]: *** [CMakeFiles/test2.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/test2.dir/all] Error 2
make: *** [all] Error 2
To copy to clipboard, switch view to plain text mode
The InteractiveQGraphicsLineItem object is declared as
#ifndef INTERACTIVEQGRAPHICSLINEITEM_H
#define INTERACTIVEQGRAPHICSLINEITEM_H
#include <QSharedData>
#include "AbstractInteractiveQGraphicsItem.h"
class InteractiveQGraphicsLineItemData;
class InteractiveQGraphicsLineItem : public AbstractInteractiveQGraphicsItem
{
public:
InteractiveQGraphicsLineItem
(AbstractInteractiveQGraphicsCoordinationItem
* parent
= 0,
QGraphicsScene* scene
= 0);
InteractiveQGraphicsLineItem(const InteractiveQGraphicsLineItem & other) : d(other.d) {}
virtual ~InteractiveQGraphicsLineItem() {}
virtual QRectF boundingRect
() const;
virtual void setDrawNewRectOnClickOutOfTheFrame(bool b);
virtual void setLine(const QLineF& line);
virtual void setLineColor
(const QColor &color
);
virtual void setHandleFillColor
(const QColor &color
);
virtual void setHandleFrameColor
(const QColor &color
);
virtual void setMaximumHandleSize(double size);
protected:
virtual void adjustHandleSize();
virtual void keyPressEvent
(QKeyEvent* event
);
virtual void keyReleaseEvent
(QKeyEvent* event
);
virtual void updateHandles();
protected:
QSharedDataPointer<InteractiveQGraphicsLineItemData> d;
};
#endif // INTERACTIVEQGRAPHICSLINEITEM_H
#ifndef INTERACTIVEQGRAPHICSLINEITEM_H
#define INTERACTIVEQGRAPHICSLINEITEM_H
#include <QSharedData>
#include "AbstractInteractiveQGraphicsItem.h"
class QGraphicsScene;
class QRectF;
class QColor;
class QLineF;
class QPainter;
class QStyleOptionGraphicsItem;
class QWidget;
class QGraphicsSceneHoverEvent;
class QGraphicsSceneMouseEvent;
class QKeyEvent;
class QGraphicsSceneWheelEvent;
class InteractiveQGraphicsLineItemData;
class InteractiveQGraphicsLineItem : public AbstractInteractiveQGraphicsItem
{
public:
InteractiveQGraphicsLineItem(AbstractInteractiveQGraphicsCoordinationItem* parent = 0, QGraphicsScene* scene = 0);
InteractiveQGraphicsLineItem(const InteractiveQGraphicsLineItem & other) : d(other.d) {}
virtual ~InteractiveQGraphicsLineItem() {}
virtual QRectF boundingRect() const;
virtual QLineF getLine();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual void setDrawNewRectOnClickOutOfTheFrame(bool b);
virtual void setLine(const QLineF& line);
virtual void setLineColor(const QColor &color);
virtual void setHandleFillColor(const QColor &color);
virtual void setHandleFrameColor(const QColor &color);
virtual void setMaximumHandleSize(double size);
protected:
virtual void adjustHandleSize();
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
virtual void updateHandles();
protected:
QSharedDataPointer<InteractiveQGraphicsLineItemData> d;
};
#endif // INTERACTIVEQGRAPHICSLINEITEM_H
To copy to clipboard, switch view to plain text mode
The declaration of the data object looks like
#ifndef INTERACTIVEQGRAPHICSLINEITEMDATA_H
#define INTERACTIVEQGRAPHICSLINEITEMDATA_H
#include <QSharedData>
#include <QRectF>
#include <QLineF>
#include <QPointF>
#include <QVector>
#include <QColor>
class InteractiveQGraphicsLineItemData
: public QSharedData{
public:
InteractiveQGraphicsLineItemData();
InteractiveQGraphicsLineItemData(const InteractiveQGraphicsLineItemData & other) {}
~InteractiveQGraphicsLineItemData() {}
bool mouseDown;
bool newSelection;
bool drawNewLineOnClickOutOfTheFrame;
double handleSize;
double maximumHandleSize;
QRectF LineHandle1, LineHandle2;
QVector<QRectF*> handles;
};
#endif // INTERACTIVEQGRAPHICSLINEITEMDATA_H
#ifndef INTERACTIVEQGRAPHICSLINEITEMDATA_H
#define INTERACTIVEQGRAPHICSLINEITEMDATA_H
#include <QSharedData>
#include <QRectF>
#include <QLineF>
#include <QPointF>
#include <QVector>
#include <QColor>
class InteractiveQGraphicsLineItemData : public QSharedData
{
public:
InteractiveQGraphicsLineItemData();
InteractiveQGraphicsLineItemData(const InteractiveQGraphicsLineItemData & other) {}
~InteractiveQGraphicsLineItemData() {}
QLineF line;
bool mouseDown;
bool newSelection;
bool drawNewLineOnClickOutOfTheFrame;
double handleSize;
double maximumHandleSize;
QRectF* mouseOverHandle;
QPointF dragStartPoint;
QLineF lineBeforeDrag;
QColor lineColor;
QColor handleFillColor;
QColor handleFrameColor;
QRectF LineHandle1, LineHandle2;
QVector<QRectF*> handles;
};
#endif // INTERACTIVEQGRAPHICSLINEITEMDATA_H
To copy to clipboard, switch view to plain text mode
and the main.cpp
#include <QCoreApplication>
#include "InteractiveQGraphicsLineItem.h"
int main(int argc, char** argv)
{
InteractiveQGraphicsLineItem foo;
return app.exec();
}
#include <QCoreApplication>
#include "InteractiveQGraphicsLineItem.h"
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
InteractiveQGraphicsLineItem foo;
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I think this is all the relevant information. Strange enough, I have a almost identical class which defines a Rect instead of a Line, and that class compiles fine even without any copy constructor. Can anyone help me?
Bookmarks