Skip to content

Commit 2c94a67

Browse files
authored
Fix memory leake by passing parent to FlowScene (paceholder#151) (paceholder#155)
1 parent 5c6321e commit 2c94a67

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

examples/calculator/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
100100
QVBoxLayout *l = new QVBoxLayout(&mainWidget);
101101

102102
l->addWidget(menuBar);
103-
auto scene = new FlowScene(registerDataModels());
103+
auto scene = new FlowScene(registerDataModels(), &mainWidget);
104104
l->addWidget(new FlowView(scene));
105105
l->setContentsMargins(0, 0, 0, 0);
106106
l->setSpacing(0);

include/nodes/internal/FlowScene.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class NODE_EDITOR_PUBLIC FlowScene
3131
Q_OBJECT
3232
public:
3333

34-
FlowScene(std::shared_ptr<DataModelRegistry> registry =
35-
std::make_shared<DataModelRegistry>());
34+
FlowScene(std::shared_ptr<DataModelRegistry> registry,
35+
QObject * parent = Q_NULLPTR);
36+
37+
FlowScene(QObject * parent = Q_NULLPTR);
3638

3739
~FlowScene();
3840

src/FlowScene.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,22 @@ using QtNodes::PortType;
3636
using QtNodes::PortIndex;
3737
using QtNodes::TypeConverter;
3838

39+
3940
FlowScene::
40-
FlowScene(std::shared_ptr<DataModelRegistry> registry)
41-
: _registry(registry)
41+
FlowScene(std::shared_ptr<DataModelRegistry> registry,
42+
QObject * parent)
43+
: QGraphicsScene(parent)
44+
, _registry(registry)
4245
{
4346
setItemIndexMethod(QGraphicsScene::NoIndex);
4447
}
4548

49+
FlowScene::
50+
FlowScene(QObject * parent)
51+
: FlowScene(std::make_shared<DataModelRegistry>(),
52+
parent)
53+
{}
54+
4655

4756
FlowScene::
4857
~FlowScene()

0 commit comments

Comments
 (0)