brcain
8th December 2006, 01:43
Short version ...
I need to prevent Qt from deleting a window that was added to a QWorkspace via QWorkspace::addWindow().
Long version ...
class cPlatView : public QDialog, public Ui::cPlatView, public cView
{
// ...
};
// ...
boost::shared_ptr<cPlatView> somePlatView;
// ...
mMainWindow->addView(somePlatView.get());
I'm using an MVC architecture where the controller manages the lifecycle of the model and the view (view being a window in the instance). The controller code (a non-Qt library) uses Boost::shared_ptr to manage memory of the model and view instances. Since the Qt addWindow call handles a naked pointer (retreived from controller by dereferencing Boost::shared pointer), Boost doesn't know that Qt has a reference to the view. So, during shutdown, the view is deleted twice ... once by Boost::shared_ptr and once by Qt.
To prevent double-delete ... how do I tell Qt not to delete memory for the view? Do I remove the window for the QWorkspace? Or do I call view::setParent(0)?
I need to prevent Qt from deleting a window that was added to a QWorkspace via QWorkspace::addWindow().
Long version ...
class cPlatView : public QDialog, public Ui::cPlatView, public cView
{
// ...
};
// ...
boost::shared_ptr<cPlatView> somePlatView;
// ...
mMainWindow->addView(somePlatView.get());
I'm using an MVC architecture where the controller manages the lifecycle of the model and the view (view being a window in the instance). The controller code (a non-Qt library) uses Boost::shared_ptr to manage memory of the model and view instances. Since the Qt addWindow call handles a naked pointer (retreived from controller by dereferencing Boost::shared pointer), Boost doesn't know that Qt has a reference to the view. So, during shutdown, the view is deleted twice ... once by Boost::shared_ptr and once by Qt.
To prevent double-delete ... how do I tell Qt not to delete memory for the view? Do I remove the window for the QWorkspace? Or do I call view::setParent(0)?