just a part of a usual structured class in Qt:
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget *parent = 0);
.
.
.
}
Looking at the constructor I don't understand the meaning of the parameter (QWidget *parent = 0)
? What does this mean?
greetings
MyClass(QWidget *parent = 0)
defines a constructor that can take a QWidget*
.
You might be confused at the = 0
part, which is C++ syntax for default arguments. Default arguments allow you to use the function without having to specify that particular argument. In the case of this, you could call this constructor like this:
mc = MyClass();
And this is equivalent to calling:
mc = MyClass(0); // or MyClass(NULL)
And that means that MyClass
object will have no parent QWidget
, because = 0
means the parent is a null pointer.
When you construct a new MyClass, you give it a pointer to a QWidget that you want to be the parent of the new one. The = 0
means that if you do not supply an argument, it will have no parent. Or, more strictly speaking, its parent pointer will be set to NULL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With