Results 1 to 8 of 8

Thread: How to destroy an object right

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to destroy an object right

    I still don't have full control of it. I'm trying to clear a layout from widgets. In the documentation it says

    Qt Code:
    1. QLayoutItem * child;
    2. while ((child = layout()->takeAt(0)) != 0)
    3. {
    4. delete child;
    5. }
    To copy to clipboard, switch view to plain text mode 

    would safely clear a layout. When I use this, the widgets still stay on the screen. So I figure I need to cast the QLayoutItem* pointers to pointers to widgets of my kind, say MyWidget*. When I do that before deleting, the program crashes. Do I need to cast here actually?

    Before I saw this in the documentation, I used an approach based on removeWidget(widget), but for that I need to keep a list of pointers to the widgets I added to the layout. It would be much more elegant to rely on the list of pointers that the layout itself is keeping.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to destroy an object right

    QLayoutItem represents an item in the layout. It's not a pointer to the widget. See QLayoutItem::widget(). But what are you actually trying to do? These kind of layout modifications tend to be problematic in terms of flickering etc. Perhaps you could just use a QStackedWidget?
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Cruz (22nd January 2009)

  4. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to destroy an object right

    I have a lot of QFrames coming in from an external source. They are placed on a widget say in a frame pool, so that the user can select a few of them and drag them somewhere else. After that the pool is cleared and new frames are coming in. So I'm looking for a short way to clear out the pool and the takeAt() method came to my attention.

    Thanks for the hint, it works really well now. There is no flicker and I don't need to maintain an internal data structure to keep track of the frames.

Similar Threads

  1. Getting std::string object from QString object ( qt3)
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 28th March 2013, 20:09
  2. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 17:31
  3. A form returning an object.
    By cbarmpar in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 05:21
  4. Object Not destroy
    By Sudhanshu Sharma in forum Qt Programming
    Replies: 3
    Last Post: 30th July 2008, 23:16
  5. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 06:33

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.