Results 1 to 2 of 2

Thread: Problems with copy constructor

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 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,519 Times in 1,389 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, 00:06
  2. Q_INTERFACES with classes having a copy constructor
    By Mike in forum Qt Programming
    Replies: 0
    Last Post: 31st October 2008, 12:40
  3. QObject and copy Constructors
    By December in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 16:14
  4. QTextEdit - copy and paste problems in X11
    By chezifresh in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 19:21
  5. QVector copy constructor
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 17: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.