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. C++ QObject’s Child Management
Forum Updated to NodeBB v4.3 + New Features

C++ QObject’s Child Management

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.3k Views 1 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.
  • A Offline
    A Offline
    annitaleo
    wrote on last edited by
    #1

    @
    #include <QApplication>
    #include <QLabel>
    #include <QVBoxLayout>
    #include <QTextEdit>
    #include <QWidget>

    int main (int argc, char* argv[]) {
    QApplication app (argc, argv);
    QWidget window;

    QLabel* label = new QLabel("Please enter some text");
    QTextEdit* textEdit = new QTextEdit;
    
    QVBoxLayout* layout = new QVBoxLayout;
    layout->addwidget(label);
    layout->addwidget(textEdit);
    window.setLayout(layout);
    window.show;
    
    return app.exec&#40;&#41;;
    

    }
    @

    Questions:

    1.Qt provides a child management facility through the QObject class. Where is the QObject in the program above? Explain

    2.The QObject class provides the function setParent(QObject *parent) to specify a Qbject to be its parent. Why is this function not use in this program?

    3.The program uses both heap and stack objects. Explain how the parnt-child facility works when the:

    a.parent is a heap obhect and the child objects are stack objects
    b.parent is a stack obhect and the child objects are heap objects

    [Edit:Please, wrap code in @ tags /Vass]

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      That sounds like a verbatim copy of a assignment;-)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        annitaleo
        wrote on last edited by
        #3

        no it is exam revision

        1 Reply Last reply
        0
        • A Offline
          A Offline
          annitaleo
          wrote on last edited by
          #4

          My answer is:

          1. For the child management, the QObject has to pass reference to the child, for example:

          @QWidget window;
          QLabel* label = new QLabel("Please enter some text",&window);
          QTextEdit* textEdit = new QTextEdit(&window);
          QVBoxLayout* layout = new QVBoxLayout(&window);@

          in this way they are registered in a window object, and whenever window is deleted, those objects will be deleted as well.

          I want to make sure is correct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            You are so lazy.. even to use "code" brackets? :)

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              Why are you not asking the people that are paid to teach you?

              How about proposing an answer for us to discuss?

              Where are your questions on the topic?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on last edited by
                #7

                You got the first one wrong... The code is OK as is I think.

                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