Results 1 to 7 of 7

Thread: Object or pointer to object?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    102
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Object or pointer to object?

    Quote Originally Posted by stampede View Post
    It will be deleted automatically when it goes out of scope.
    Thanks I know that, but can it be deleted while still in scope. It is not that I really need this, but would just like to make clear what can and what can't be done, thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Object or pointer to object?

    No, it cannot. The definition of a local variable is that its life is determined by the scope of its declaration. But you can limit the scope if you want.

    Qt Code:
    1. Cat *tofi = new Cat();
    2. {
    3. Cat smuki;
    4.  
    5. delete tofi; //object on the heap deleted ok
    6. } // smuki undeclared past this point
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2013
    Posts
    102
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Object or pointer to object?

    No, it cannot. The definition of a local variable is that its life is determined by the scope of its declaration. But you can limit the scope if you want.

    Qt Code:
    Switch view

    Cat *tofi = new Cat();
    {
    Cat smuki;

    delete tofi; //object on the heap deleted ok
    } // smuki undeclared past this point
    Very good, thanks.

Similar Threads

  1. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 05:54
  2. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 17:31
  3. static Object Vs Pointer
    By rajeshs in forum General Programming
    Replies: 4
    Last Post: 11th June 2008, 07:41
  4. Saving object pointer
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 11th January 2008, 11:53
  5. Pointer to ActiveX object in QT
    By json84 in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2007, 12:42

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
  •  
Qt is a trademark of The Qt Company.