Solved Class
-
As I already suggested, use the debugger.
-
@SGaist
Yeah I know, and thanks for the help:), I already fixed my code as I mentioned above, but I don't understand what I fixed:/ -
If you are talking about the QVector snippet, you did not fix anything, you broke QVector.
-
@privatepepper
Your comment-out code preventsQVector<T>::clear()
from actually clearing its elements, and then your code works. I would look at everywhere you use aQVector
. You havematrix->clear();
; just what do you do with yourQVector <int> *matrix
? It is a member variable right next to where you introduce a new variable and then it crashes....matrix->clear(); ... matrix = new QVector <int> [nodes];
What about first time round? You do initialize
matrix
before this, don't you, else you're trying toclear()
a random area of memory.... -
-
There is also no need to use a pointer here.
-
@Christian-Ehrlicher said in Class:
There is also no need to use a pointer here.
Do you mean
QVector <int> *matrix
? I added this pointer because I want that this vector would be 2d -
Then use
QVector<QVector<int>> matrix
-
Okay, I will use
QVector<QVector<int>> matrix
, but why I shouldn't use a pointer? Is there a big difference? Sorry for dumb questions... -
@privatepepper said in Class:
but why I shouldn't use a pointer?
Because it's not needed and when using an object you can't forget to initialize (and delete) it (as you did both)