Results 1 to 7 of 7

Thread: QPointer and double deletion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPointer and double deletion

    I have a
    Qt Code:
    1. QList<QPointer<MTR::RowBox> > rowBoxes;
    To copy to clipboard, switch view to plain text mode 
    that is a private member of my main widget.
    I want to store pointers to a few widgets in this list as well as I want to place these widgets in a gridLayout. My concern is connected to possible double deletion of these widgets as first may be done by a parent widget (received by layout) and second may be done by QList.

    I receive SIGSEV for this code:
    Qt Code:
    1. QGridLayout *qgl = new QGridLayout();
    2. pawnBox = new MTR::PawnBox();
    3.  
    4. QPointer<MTR::RowBox> rbOne = new MTR::RowBox();
    5. rowBoxes.push_back(rbOne);
    6. QPointer<MTR::RowBox> rb2 = new MTR::RowBox();
    7. rowBoxes.push_back(rb2);
    8. QPointer<MTR::RowBox> rb3 = new MTR::RowBox();
    9. rowBoxes.push_back(rb3);
    10.  
    11. QWidget *w1 = new QWidget();
    12. w1->setFixedSize(50,50);
    13. qgl->addWidget(w1,0,0,1,2);
    14. qgl->addWidget(rbOne,1,0);
    15. qgl->addWidget(pawnBox,1,1,3,1);
    16. qgl->addWidget(rb2,2,0);
    17. qgl->addWidget(rb3,3,0);
    18. gameScreen->setLayout(qgl);
    To copy to clipboard, switch view to plain text mode 

    where MTR::RowBox is a pure subclass of a QWidget.

    Backtrace is obvious:
    Qt Code:
    1. #0 0x080559d6 in QList<QPointer<MTR::RowBox> >::~QList ()
    2. #1 0x08052eb7 in MyWidget::~MyWidget ()
    3. #2 0x0804e89e in main ()
    To copy to clipboard, switch view to plain text mode 

    A quotation from QPointer class documentation:
    Guarded pointers are useful whenever you need to store a pointer to a QObject that is owned by someone else, and therefore might be destroyed while you still hold a reference to it.
    Last edited by mtrpoland; 28th September 2007 at 11:02.

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.