I have a function:

mkPan();

that makes all the Information panels for my Qt Application. The panels are QFrames with one or more QLabels made up of QStrings and/or QPixmaps. I define the components of a particular panel in my .h file like so:

Qt Code:
  1. QFrame *panFra1;
  2. QLabel *panLab1;
  3. QString *panStr1;
To copy to clipboard, switch view to plain text mode 

I'd like to free-up / clean-up memory by deleting everything but the QFrame after it's been made. I've noticed that I can do this with QStrings: after defining a QLabel and setTexting it with a QString, I can then delete the QString. Presumably the QString is rasterized on the QLabel, and there's thus no longer any need to keep it (the QString) around. (And I can therefore simply create QString's on the stack within the mkPan() function and don't need to declare pointers to them in the .h file.) If I try the same with the QLabels, however: they don't show up on the QFrame. Is there a way to 'rasterize' the QLabels onto the QFrame so I don't need to keep them around? ...or is this even something I should worry about.

One last thing: I'd want to stop declaring the QLabel's in the .h file and simply declare them in the mkPan() function as needed. Is this OK:

Qt Code:
  1. mkPan()
  2. {
  3. if(panType == 7)
  4. {
  5. for(int a=0; a<numberOfLabelsThisPanel; a++)
  6. {
  7. QLabel *tempLab = new QLabel;
  8. tempLab->setText(panStr);
  9. // etc...
  10. // delete tempLab; // this I cannot do
  11. }
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

...i've left some stuff out here, including methods for getting the appropriate QString value, but the crux of my question is: can I declare "QLabel *tempLab" over and over again... or do they have to be unique names?