I’m having some issues in allocating memory for an array dynamically in C++ within Qt SDK … Here’s for I’m doing:
int dx = 5;
QPoint * qPoint;
qPoint = new QPoint[dx+1];
However when I try to debug the code, the programs just crashes when it tries to execute the third line …. any clues ?
If you want to use Qt SDK properly you have to use QVector instead of C++ arrays or std arrays. You can use QVector as a pointer or not, it doesn’t really matter since internally it will allocate the memory dynamically.
For example:
You can also do:
In case you want the vector as a pointer. But Qt uses implicit memory sharing for vectors so you can use the first approach most of the times.
http://doc.qt.io/qt-5/implicit-sharing.html#implicit-data-sharing