MCPcopy Create free account
hub / github.com/KDAB/GammaRay / reparent

Function reparent

tests/manual/objectreparenttest.cpp:18–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#include <QTimer>
17
18class MyObject : public QObject
19{
20 Q_OBJECT
21public:
22 explicit MyObject(QObject *parent = nullptr)
23 : QObject(parent)
24 , c(new QObject(this))
25 , p1(new QObject(this))
26 , p2(new QObject(this))
27 {
28 c->setObjectName(QStringLiteral("MovingSubtree"));
29
30 auto t = new QTimer(this);
31 t->start(10000);
32 connect(t, &QTimer::timeout, this, &MyObject::reparent);
33
34 auto gc = new QObject(c);
35 new QObject(gc);
36 c->setParent(p1);
37 }
38
39public slots:
40 void reparent()
41 {
42 if (c->parent() == p1)
43 c->setParent(p2);
44 else if (c->parent() == p2)
45 c->setParent(nullptr);
46 else
47 c->setParent(p1);
48 }
49
50private:
51 QObject *c, *p1, *p2;

Callers

nothing calls this directly

Calls 2

setParentMethod · 0.80
parentMethod · 0.45

Tested by

no test coverage detected