Results 1 to 2 of 2

Thread: Problems with copy constructor

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    369
    Thanks
    87
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Problems with copy constructor

    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.

    Qt Code:
    1. class KeyFrame : public QFrame
    2. {
    3. int id;
    4. public:
    5. KeyFrame(QWidget *widget);
    6. virtual ~KeyFrame();
    7. int getId();
    8. }
    9.  
    10.  
    11. main
    12. {
    13. KeyFrame kf(ui.someWidget);
    14.  
    15. QList<KeyFrame> frameBuffer;
    16. frameBuffer.append(kf); // BOOM
    17. }
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problems with copy constructor

    QObject, the base class of QWidget, cannot be copied. You can store pointers, not values.
    J-P Nurmi

Similar Threads

  1. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 01:06
  2. Q_INTERFACES with classes having a copy constructor
    By Mike in forum Qt Programming
    Replies: 0
    Last Post: 31st October 2008, 13:40
  3. QObject and copy Constructors
    By December in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 17:14
  4. QTextEdit - copy and paste problems in X11
    By chezifresh in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 20:21
  5. QVector copy constructor
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.