Results 1 to 4 of 4

Thread: copying and assignment constructors

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default copying and assignment constructors

    Hello all,
    I can guess that the following warning it's not very important but how can I avoid it?

    I derive a class from some base class. The compiler tells me that the copy constructor could not be generated for the base class. I get a similar second warning about the assignment operator.

    The concrete example:
    Qt Code:
    1. class SliderWidget :public QGroupBox
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. SliderWidget(Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0 ):QGroupBox(parent)
    7. {
    8. // here I call new for some widgets and do the connect stuff
    9. }
    10. //there is no destructor defined
    11. };
    To copy to clipboard, switch view to plain text mode 

    What would a copy constructor look like? Do I call new set all the member variables in the new instance and pass it back as the copy?
    An assignement operator? Do I have to so the same as in the copy constructor?
    thanks
    K

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: copying and assignment constructors

    You can't copy QObjects.

  3. The following 2 users say thank you to jacek for this useful post:

    sunil.thaha (17th August 2006), TheKedge (17th August 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: copying and assignment constructors

    Well, that's great news, actually. So, the warnings are essentially meaningless and I can't avoid them anyway, and I'm doing everything right.
    Would that sum it up?
    It's great being able to ignore things.
    thanks for the prompt reply.
    K

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: copying and assignment constructors

    Quote Originally Posted by TheKedge
    So, the warnings are essentially meaningless and I can't avoid them anyway, and I'm doing everything right.
    Not quite, if you can't copy the base class, you can't copy the derived class too. In other words, you shouldn't implement copy constructor and assignment operator, because they won't work.

  6. The following user says thank you to jacek for this useful post:

    sunil.thaha (17th August 2006)

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.