renaudjenny / MBTI

First tryout with Qt, Read XML File, use some Qt Widgets
0 stars 0 forks source link

Many memory management issue #1

Open renaudjenny opened 9 years ago

renaudjenny commented 9 years ago

After a few Qt experiences and extern remarks about memory management, I notice many mistakes related to memory management.

Giorgiolino commented 9 years ago

"many mistakes" ... like what ?

renaudjenny commented 9 years ago

Like using pointers vs object. It's safer to use objects when we can. And I think it's better to set directly the QWidget parent when you initialise it Like

//.h
class MyClass
{
private:
    QWidget* m_mainView;
}

//.cpp
MyClass::MyClass()
{
    m_mainView = new QWidget;
    QLabel* aLabel = new QLabel(mainView);
    ...
}

MyClass::~MyClass()
{
    delete m_mainView;
}