This question is from a past exam paper and it is used for revision purposes
#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();
}
-
Qt provides a child management facility through the QObject class. Where is the QObject in the program above? Explain
-
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?
-
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
QObject documentation is available here, and can also be accessed via Qt assistant. So go ahead and read it.