Results 1 to 3 of 3

Thread: Why have they put the constructor of QObject and QLayout "PRIVATE"????

  1. #1
    Join Date
    Jun 2017
    Qt products
    Qt3 Qt5

    Default Why have they put the constructor of QObject and QLayout "PRIVATE"????

    Hello people! Don't you see that the fact that constructors of some object like QObject,QLayout are private make that can't use QVector for using loops on sub class of QObject which will shorcut the code? I mean for example :
    Qt Code:
    1. QVector <QWidget> widow (100);
    2. for (i=o;i <100;i++)layout->addWidget (&widow [i]);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Thanked 54 Times in 52 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows

    Default Re: Why have they put the constructor of QObject and QLayout "PRIVATE"????

    Hi, you can do that by using a vector of pointers.


  3. #3
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 678 Times in 668 Posts
    Qt products
    Windows Android

    Default Re: Why have they put the constructor of QObject and QLayout "PRIVATE"????

    The copy constructor and assignment operator are private, not the basic constructor. These are private to prevent copying. QObject-based class instances have a parent-child hierarchy; that is, an instance of a QObject class has a parent and itself can have children. If assignment and copying were allowed, this would mean that an instance could have multiple parents (or that different parents could have the same children). Parents own and control the lifetimes of their children, so a case where a child had more than one parent would not work.

    As Ginsengelf says, nothing prevents you from assigning and copying pointers to QObject instances. This is exactly how the parent-child relationship is implemented - the parent holds pointers to its children, and a child holds a pointer to its parent.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 27th January 2012, 18:29
  2. Replies: 1
    Last Post: 5th February 2011, 22:14
  3. Replies: 0
    Last Post: 20th September 2010, 10:58
  4. Replies: 2
    Last Post: 6th October 2009, 02:09
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05


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.