Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the significance of following constructor myView::myView(MyMainWindow* parent):QWidget(NULL)
Forum Updated to NodeBB v4.3 + New Features

What is the significance of following constructor myView::myView(MyMainWindow* parent):QWidget(NULL)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 713 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by Qt Enthusiast
    #1

    If I have a class

    class myMainWindow: public QMainWindow() {
    }
    class myView: public QWidget {
    myView(myMainWindow* parent);
    }

    what is difference between three constructors

    myView:myView(myMainWindow* parent): QWidget(parent) {
    }

    or
    myView:myView((myMainWindow* parent):):QWidget(NULL) {
    }
    or
    myView:myView(myMainWindow* parent) .

    Could you let me know what is significance of each

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      myView:myView(myMainWindow* parent): QWidget(parent) {

      Give the parent to the Base class

      myView:myView((myMainWindow* parent):):QWidget(NULL)

      Give no parent to base class. THIS YOU SHOULD NEVER DO. EVER. not like that

      if u want no parent, call like this
      new myView(NULL);

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        So If I have call like

        class myMainWindow:QMainWindow{
        }

        class mytableView: public QtableView {
        protected:
        virtual void keyPressEvent(QKeyEvent *event);

        };
        class myView: public QWidget {
        myView(A*,QString title, myMainWindow*)
        private:
        A* d_a;
        MyMainWindow* d_parent ;
        mytableView* table;
        }

        myView::myView(Aa ,QString title,myMainWindow parent ) : d_a(a),d_parent(parent)
        {
        setWindowTitle(title);
        table = new mytableView;
        }
        mytableView:keyPressEvent(QKeyEvent *event) {
        ...
        ...
        }

        What is the problem in this code for parent child relation

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          why would you ever do that ??
          Just call your baseclass constructor as you should.
          Its how it works and you are also free to have parent * as variable but
          you should always call BaseClass constructor with the given parent.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved