You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, April 30th 2013, 7:39am

deleting QPushbuttons and other objects

I have a class holding several Qobjects. when i delete the class object the internal mebers will get deleted or not
below is sample example i wrote.

doing delete on app will delete button and label or not
or do i need to write delete button[no] and delete label[no] in the destructor

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class apps {

	private :
	QPushButton *button[20];
	QLabel* name[20];
	
	public:
	create_buttons();
	
};


apps :: apps()
{
	/* */	
}


apps :: ~apps ()
{

}

void apps :: create_button()
{
	
	//no = 1 to 9
	button[no] = new QPushButton();
        name[no]= new QLabel();


}

apps *app;

app = new apps;
  
 delete app;

_Blueman

Intermediate

  • "_Blueman" is male

Posts: 196

Location: Poland

  • Send private message

2

Tuesday, April 30th 2013, 7:29pm


3

Thursday, May 2nd 2013, 7:07am



When you create a QObject with another object as parent, the object will automatically add itself to the parent's children() list. The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor.

Thanks a lot.

4

Thursday, May 2nd 2013, 7:10am

How to thank repliers on this forum :)

_Blueman

Intermediate

  • "_Blueman" is male

Posts: 196

Location: Poland

  • Send private message

5

Thursday, May 2nd 2013, 3:27pm

just help other people if you know the answer :)