Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Ownership with Q3DSurface
Qt 6.11 is out! See what's new in the release blog

Ownership with Q3DSurface

Scheduled Pinned Locked Moved Solved General and Desktop
q3dsurfaceparentchildrendestroy
3 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #1

    Hi everybody,
    i use the Q3DSurface class, but i'm not quite sure if i need to destroy the instances in the destructor or not.

    MyClass.h

    class MyClass : public QMainWindow
    {
    	Q_OBJECT
    public:
    	MyClass(QWidget*parent = 0);
    	~MyClass();
    
    private:
    	Ui::MyClass_GUIClass ui;
    
    	Q3DSurface					*m_graph;
    	QWidget 					*m_grapWidget;
    
    	MyAbstractListModel			*m_model;
    	QItemModelSurfaceDataProxy	*m_proxy;
    	QSurface3DSeries			*m_series;
    }
    

    MyClass.cpp

    MyClass::MyClass(QWidget*parent) : QMainWindow(parent)
    {
    	ui.setupUi(this);
    
    	m_graph = new Q3DSurface();
    	m_graphWidget = QWidget::createWindowContainer(m_graph);
    	ui.verticalLayout->addWidget(m_graphWidget);
    
    	m_model= new MyAbstractListModel();
    	m_proxy= new QItemModelSurfaceDataProxy(m_model, QStringLiteral("radius"), QStringLiteral("angle"), QStringLiteral("value"));
    
    	m_series = new QSurface3DSeries(m_proxy);
    
    	m_graph->addSeries(m_series);
    
    	fillModelWithData();
    }
    
    MyClass::~MyClass()
    {
    	// do i need to destroy something?
    }
    

    Thanks !

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi!

      m_graphWidget = QWidget::createWindowContainer(m_graph);
      

      The container m_graphWidget takes ownership of m_graph.

      ui.verticalLayout->addWidget(m_graphWidget);
      

      This will make m_graphWidget a child of the widget that holds verticalLayout.

      m_model= new MyAbstractListModel();
      

      m_model doesn't have a parent.

      m_proxy= new QItemModelSurfaceDataProxy(m_model, QStringLiteral("radius"), QStringLiteral("angle"), QStringLiteral("value"));
      

      The proxy doesn't take ownership of the itemModel and you don't give a parent to QItemModelSurfaceDataProxy().

      m_series = new QSurface3DSeries(m_proxy);
      m_graph->addSeries(m_series);
      

      You don't pass a parent to QSurface3DSeries().
      Looking at the docs it's not clear to me whether or not addSeries reparents it. But it wouldn't matter anyways if you'd pass a parent to QSurface3DSeries().

      ------------------------------

      • m_graph and m_graphWidget already get destroyed automatically
      • Pass a parent to MyAbstractListModel()
      • Pass a parent to QItemModelSurfaceDataProxy()
      • Pass a parent to QSurface3DSeries()
      beeckscheB 1 Reply Last reply
      3
      • ? A Former User

        Hi!

        m_graphWidget = QWidget::createWindowContainer(m_graph);
        

        The container m_graphWidget takes ownership of m_graph.

        ui.verticalLayout->addWidget(m_graphWidget);
        

        This will make m_graphWidget a child of the widget that holds verticalLayout.

        m_model= new MyAbstractListModel();
        

        m_model doesn't have a parent.

        m_proxy= new QItemModelSurfaceDataProxy(m_model, QStringLiteral("radius"), QStringLiteral("angle"), QStringLiteral("value"));
        

        The proxy doesn't take ownership of the itemModel and you don't give a parent to QItemModelSurfaceDataProxy().

        m_series = new QSurface3DSeries(m_proxy);
        m_graph->addSeries(m_series);
        

        You don't pass a parent to QSurface3DSeries().
        Looking at the docs it's not clear to me whether or not addSeries reparents it. But it wouldn't matter anyways if you'd pass a parent to QSurface3DSeries().

        ------------------------------

        • m_graph and m_graphWidget already get destroyed automatically
        • Pass a parent to MyAbstractListModel()
        • Pass a parent to QItemModelSurfaceDataProxy()
        • Pass a parent to QSurface3DSeries()
        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @Wieland
        Thanks for the informations!

        In the Surface Example they only delete the Q3DSurface instance.

        But i will pass the parents to the classes, so i can be sure, that they are destroyed. Thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved