[Qt-interest] Don't understand QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) : QObject(*new QWidgetPrivate, 0)

Andreas Pakulat apaku at gmx.de
Thu Jul 1 16:49:55 CEST 2010


On 01.07.10 16:40:19, Kustaa Nyholm wrote:
> This is going to expose my ignorance but I don't follow this
> from QWidget.cpp:
> 
> 
> In the constructor of QWidget
> 
> QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) : QObject(*new
> QWidgetPrivate, 0)
> 
> Several things I don't understand here. QObject only has one constructor
> that takes one argument so how the base class QObject is initialized with
> two arguments?

No it doesn't. Look again, there's a protected constructor that takes in a
reference-to-QObjectPrivate and a parent.

> And why is parent not passed there?

I can only guess (you could look into the init() function in the private
class to find out more), but maybe the QObject constructor would do the
wrong thing when passed a qwidget parent. Instead the init function on the
qwidgetprivate is being used.

> And why the derefenring
> of the new QWidgetPrivate?

Because the constructor in QObject takes a reference to the object, not a
pointer.

> Is this some C++ syntax mystery that I'm no awera of or what....?

No not at all.

Andreas 

-- 
You are always busy.



More information about the Qt-interest-old mailing list