开发者

Qt - What do we mean by those code snippets

I just have those questions about those code sinppets from the C++ GUI Programming with Qt 4 book:

GoToCellDialog::GoToCellDialog(QWidget *parent):QDialog(parent)

Does th开发者_Python百科at mean we are inheriting QDialog(parent)? Or, what exactly does this mean?

setupUi(this);

Here, this code snippet is part of the gotocelldialog.cpp file, which is the implementation of gotocelldialog.h header file. What do we mean by this in this context? What are we trying to setup? And, what kind of setup will that be?

Thanks.


GoToCellDialog::GoToCellDialog(QWidget *parent) : QDialog(parent)

: signifies an initializer list. And it meant, parent is being passed as a parameter to QDialog constructor. I assume GoToCellDialog is derived from QDialog and so sending parent to it's constructor. So, before even body of GoToCellDialog is executed, QDialog constructor is executed.

This example should give you an idea -

class foo
{
    int number ;
    public:
        foo(int i) : number(i) // Means copying value of i to number
        {}
};

class bar : public foo
{
    public:
        bar(int temp) : foo(temp)
        { // <- Before getting here, foo sub object must be constructed.
          //  Because the order of construction takes from parent to child.
        }
};

In the above example, definitely an argument for foo constructor must be passed while instantiation of bar. So, initializer list is the only way because there is no default constructor( i.e., constructor with no arguments) available for foo.


To answer your questions:

Does that mean we are inheriting QDialog(parent)?

Yes, this is basic C++ inheritance.

setupUi(this);

In short: The 'User Interface compiler' (uic) compiles/translates the xml file to C++ code which will be compiled and linked. The setupUi() function ensures that the Qt designer widgets you made (generated C++ code) are setup to be used by your code by Building the Widget tree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜