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:
QFrame *panFra1;
QLabel *panLab1;
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:
mkPan()
{
if(panType == 7)
{
for(int a=0; a<numberOfLabelsThisPanel; a++)
{
tempLab->setText(panStr);
// etc...
// delete tempLab; // this I cannot do
}
}
}
mkPan()
{
if(panType == 7)
{
for(int a=0; a<numberOfLabelsThisPanel; a++)
{
QLabel *tempLab = new QLabel;
tempLab->setText(panStr);
// etc...
// delete tempLab; // this I cannot do
}
}
}
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?
Bookmarks