{"id":549,"date":"2015-10-07T19:01:39","date_gmt":"2015-10-07T16:01:39","guid":{"rendered":"https:\/\/sobbayi.com\/?p=549"},"modified":"2015-10-07T19:01:39","modified_gmt":"2015-10-07T16:01:39","slug":"memory-management-with-qpointer-in-qt-cpp","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/memory-management-with-qpointer-in-qt-cpp\/","title":{"rendered":"Memory Management With QPointer in Qt C++"},"content":{"rendered":"

You have probably heard how it has been said that in some corporate organizations that pointers have been banned when coding in C++. Then you would know that this is really awkward for any C++ programmer to not use Objects in their code.<\/p>\n

Anyway, there is a sane way to handle your memory management issues when programming with Qt and that is to use one of the pointer classes called QPointer provided in the Qt framework.<\/p>\n

Before we go much further, this post expects you to have an idea of programming in C++ and it also expects you to know the basics of the Qt framework. If you are not familiar with what Qt is you can get an idea from The Qt Company<\/a>.<\/p>\n

If you are not familiar with C++ then I would advise you to read another article on this website about C++ and when you have time Google the word “C++” and follow on the documentation and tutorial resources available on the Internet.<\/p>\n

Before We Deal With QPointer<\/h2>\n

We will look at two general ways in which Qt manages memory and how it takes care of pointers so that we do not have to worry about it as much. I will give just a quick note on what pointers are in C++ and why they are so dangerous to use before we get on with this post.<\/p>\n

What is a C++ Pointer?<\/h2>\n

If you are already familiar with C++ then this section is not for you. However, for argument’s sake, I will still mention what a pointer is. A pointer is in simplest terms, an object that stores the memory address of another object or primitive type. Take for example:<\/p>\n