Fred K Ollinger on Tue, 16 Jul 2002 00:38:22 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] [ON TOPIC] passing a pointer to an object to an object (c++)


> On Monday 15 July 2002 08:24 am, Walt Mankowski wrote:
> > That code segfaults?  I'm surprised it even compiles.  What type is
> > qlBillBoard?  It looks like it must be QLabel.  Then you either want
> > to say
> it compiles perfectly but causes a memory leak.
>
> what you really want is a:
> qlBillBoard(qlIncoming);
> instead.  But make sure you are not deleteing your qlIncoming somewhere.
> Remember QWidgets are all QObjects and can be deleted if the parent goes
> away.

Since this is a short live installer, I'm not that worried about memory
leaks, but I would rather do w/o them.

> Your segfault is 90% sure in the fact that a new on QLabel calls show, well
> the QLabel gets pissed because your parent pointer is 0.

Got it.

> Please read the Qt docs and this will become very clear, otherwise I have done
> some Qt training, so you can fire off questions to me directly.

I wouldn't waste plug's time if I hadn't read the docs several times.

I have a QLabel *qlBillBoard, which is part of my installer wizard. I
would like to point to this in an object called voxInstallCommon, which is
called when one clicks 'finish' in the wizard.

I am able to pass the pointer to the qlBillBoard and it works great for a
single function. However, when I try to send it over in the constructor,
all hell breaks loose.

I'm going to try Jason's syntax, and see what happens.

voxWizardInstall creates a voxInstallCommon:

voxInstallCommon myinstall(*qlBillBoard);

now I want to take that pointer and point to the same memory area in the
constructor for the voxInstallCommon.

Sorry this wasn't more clear. Will this always create the memory leak?

How to avoid this? Can't I just destroy the pointer in voxInstallCommon
before voxInstallCommon is destroyed?

I think that since passing the pointer for each function works flawlessly,
I'll do that for all the functions. This is going to have another arg to a
ton of functions, but it will work properly. Is there a downside to this
besides more typing?

Thanks for all the help on this. Before you all started helping me I
didn't know quite how confused I was. Hopefully a few more rereads of
these emails will straighten this out.

Good day,

Fred



______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug