QObject* child = new QObject(); QObject* parent = new QObject(); child->setParent(parent);
QObject* parent = new QObject(); QObject* child = new QObject(parent); // Access parent object parent->setProperty("name", "John"); QString name = parent->property("name").toString(); qDebug() << name; // Output: "John"In this example, we create a new QObject called parent and set its name property to "John". We then create a new QObject called child and set its parent to be parent. Finally, we access the name property of the parent object using the property() method and output it to the console. The Qt library package contains the QObject class.