Results 1 to 4 of 4

Thread: simple question on declare

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default simple question on declare

    hi, I declare it inside mainform costructor:
    Qt Code:
    1. QLabel* label1 = new QLabel(PushButton);
    2. label1->setPixmap(QPixmap::fromMimeSource("end.png"));
    3. //put a label on a pushbutton created in Designer
    To copy to clipboard, switch view to plain text mode 
    I wonder this: when the mainForm costructor is executed, and program is out of the scope of mainform costructor, should be label1 destroyed?!?!
    If it is so: why I can see the pixmap? But I see the pixmap for all life of program....thanks.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on declare

    label1 is a pointer and indeed it gets destroyed when constructor ends, but the object that this pointer points to remains untouched --- since it was allocated using new operator, the programmer is responsible for destroying it (note: if it has a parent, it will be destroyed automatically by Qt).

    PS. Please, read some book about C++ programming --- everything will become clear for you.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: simple question on declare

    thanks; but label1 is deleted, the object pointed isn't deleted (I'm lucky because QT do this for me at the death of parent) but: is this beautiful? can it cause any problems? (not in general but with QT)
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on declare

    If you don't need to access that label later, you don't have to keep a pointer to it.

Similar Threads

  1. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  2. simple pointer question
    By mickey in forum General Programming
    Replies: 6
    Last Post: 16th June 2006, 09:19
  3. a simple question: spinbox
    By mickey in forum Newbie
    Replies: 3
    Last Post: 27th February 2006, 15:37
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.