PDA

View Full Version : Problems with copy constructor



Cruz
15th January 2009, 17:06
Hello,

I derived my own class from QFrame and now I can't put it into a QList. It complains about the copy constructor of QFrame being private.



class KeyFrame : public QFrame
{
int id;
public:
KeyFrame(QWidget *widget);
virtual ~KeyFrame();
int getId();
}


main
{
KeyFrame kf(ui.someWidget);

QList<KeyFrame> frameBuffer;
frameBuffer.append(kf); // BOOM
}





linux-g++ -I. -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include/QtOpenGL -I/usr/local/Trolltech/Qt-4.4.3/include/QtOpenGL -I/usr/local/Trolltech/Qt-4.4.3/include -I/usr/X11R6/include -Idebug -I. -o debug/MotionEditor.o MotionEditor.cpp
/usr/local/Trolltech/Qt-4.4.3/include/QtGui/qframe.h: In copy constructor ‘KeyFrame::KeyFrame(const KeyFrame&)’:
KeyFrame.h:15: instantiated from ‘void QList<T>::append(const T&) [with T = KeyFrame]’
MotionEditor.cpp:31: instantiated from here
/usr/local/Trolltech/Qt-4.4.3/include/QtGui/qframe.h:136: error: ‘QFrame::QFrame(const QFrame&)’ is private
KeyFrame.h:15: error: within this context


What should I do now? I HAVE to subclass some Widget to override the paintEvent() method and I would really like to use the nice Qt Collections.

Thanks
Cruz

jpn
15th January 2009, 17:14
QObject, the base class of QWidget, cannot be copied. You can store pointers, not values.