Results 1 to 4 of 4

Thread: children of a QFrame: possible to delete?

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default children of a QFrame: possible to delete?

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: children of a QFrame: possible to delete?

    QLabel will be needed as long as u need them. They are widgets.
    Qstring is just a class, and to set text on qlabel, u guessed right, u dont have to store a Qstring for it. u just need to call setText.

    and how many QLabels are u creating ? u need not worry much about them as Qt is quite efficient, u just need to set the right parent.

    Also u can have same name for different labels.

  3. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: children of a QFrame: possible to delete?

    Quote Originally Posted by aamer4yu View Post
    and how many QLabels are u creating ? u need not worry much about them as Qt is quite efficient, u just need to set the right parent.
    Thanks for clearing that up, '4yu. The number of QLabels varies from project-to-project: 400-500 not uncommon. For example: the attached image--a screencap from my App--has a pop-up Info panel (QFrame) comprised of 8 QLabels: 7 for the text, and one for the image. There may be 20 such panels--plus other kinds, likewise comprised of many QLabels--scattered throughout a project.

    Anyway, by your account I guess it's OK to have 500 pointers to QLabels all with the same name. I'll give it a go. Thanks again.
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: children of a QFrame: possible to delete?

    If you want to optimize, you can identiify frames / widgets which will not be shown all the time.
    You can the create those frames on the go and delete them as soon as the work is over.
    For example ur pop up window, i guess its shown on some event. You can create a separate class for the pop up window and create it when some event occur. That way u will save memory. Extra cost is, u will have to make conenctions each time.

    Also i just gave a example, am not sure how it fits into ur app needs

  5. The following user says thank you to aamer4yu for this useful post:

    vonCZ (9th September 2008)

Similar Threads

  1. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  2. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.