![]() |
2010-05-19
, 08:08
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#12
|
![]() |
2010-05-19
, 08:38
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#13
|
Parent can be any class that inherits from QObject. QWidgets are inherited from QObject, so yes.
If you create a dialog, give all member pointer variables the dialog as parent and you don't have to care about their memory
With Qt the memory handling is a lot easier than with blank c++.
![]() |
2010-05-19
, 08:45
|
Posts: 190 |
Thanked: 129 times |
Joined on Mar 2010
@ Bavaria, Germany
|
#14
|
so in constructor method i've to define:
className(parameters, QObject parent);
am i right?
MyClass::MyClass(QObject* parent) : QObject(parent) // Not passing the parent to the QObject base will also result in memory leakage { mySubObject = new QObject(this); // Will be deleted when "MyClass" dies myLeakObject = new QObject; // Will live forever }
![]() |
2010-05-19
, 08:53
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#15
|
Not sure what you mean.
example implementation code:
Code:MyClass::MyClass(QObject* parent) : QObject(parent) // Not passing the parent to the QObject base will also result in memory leakage { mySubObject = new QObject(this); // Will be deleted when "MyClass" dies myLeakObject = new QObject; // Will live forever }
![]() |
2010-05-19
, 13:46
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#16
|
![]() |
2010-05-19
, 14:27
|
|
Posts: 179 |
Thanked: 86 times |
Joined on Dec 2009
@ Barcelona
|
#17
|
while i'm bothering you with this silly questions, i've another doubt about inclusions
how to use #include? i mean it's different from java import, so using include(from what i remember) means include "piece of code"(correct if i'm wrong) and not just import a name space!
so, how to avoid duplicate include?
suppose i have main class, firstclass and secondclass, if i include secondclass in firstclass, and first class in main, does main class automatically include secondclass?
i hope u can understand what i'm trying to say
The Following User Says Thank You to damnshock For This Useful Post: | ||
![]() |
2010-05-19
, 17:11
|
Posts: 190 |
Thanked: 129 times |
Joined on Mar 2010
@ Bavaria, Germany
|
#18
|
The Following User Says Thank You to gri For This Useful Post: | ||
![]() |
2010-05-19
, 18:50
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#19
|
The Following User Says Thank You to Joorin For This Useful Post: | ||
If you create a dialog, give all member pointer variables the dialog as parent and you don't have to care about their memory
With Qt the memory handling is a lot easier than with blank c++.
PS: You could also take a look at QSharedPointer when using non-QObject classes. (or boost::shared_ptr if you don't like the Qt implementation)