tags:

views:

393

answers:

3

I'm learning Qt, found this:

Widget::Widget(QWidget *parent)
    : QWidget(parent), ui(new Ui::WidgetClass)
{
    ui->setupUi(this);
}

what is ": QWidget(parent), ui(new Ui::WidgetClass)" mean?

And how can I get the C++ document about this?

+8  A: 

This is nothing special with Qt, just part of C++.

: QWidget(parent) is just calling the base contructor.

ui(new Ui::WidgetClass) is just a member being initialized.

Example:

class B
{
public:
  B(int x)
  {
    myx = x;
  }

  int myx;
};

class D : public B
{
public:
   D() 
   : B(4), p(new char[1024])
   {
   }

   ~D()
   {
     delete[] p;
   }

   char *p;
};
Brian R. Bondy
how can I get this reference? I only had watched this: http://www.cplusplus.com/doc/tutorial/namespaces.html
linjunhalida
Most books on C++ programming will cover this
Brian R. Bondy
+4  A: 

The construct is called an initialization list and is used to initialize base classes and/or member variables in class constructors.

If you want to learn more about them (it's an essential concept in C++), see for example this document or ask 'the' google.

Ferdinand Beyer
A: 

A reference for example:
http://www.cprogramming.com/tutorial/initialization-lists-c++.html
or just google "C++ initialization"

shoosh