QVector<QVector<Node*> > strange behaviour
-
Hello, i've searched the forum, but i didn't find anything relevant to my problem:
I have a class named Node that contains QVector<QVector<Node*> > link;
and with this constructor:
@ Node(int conMax)
{
link = QVector<QVector<Node*> >(conMax);}@
and i use:
@
Node* nod = new Node(4);nod->link[2].append(anotherNode);
@well it sometimes work but sometimes, when i made a bigger test,
it crashes and gdb reports segfault in QVector<Node*>::append(Node&*)only after changing constructor to:
@ Node(int conMax)
{
link = QVector<QVector<Node*> >(conMax +4);}@
crash dissapeared. I'm afraid that for even bigger input, crash can appear again.
I do something wrong?
I need the first QVector to have a certain size, so i can could insert everywhere in that range.
-
conMax does only define the size of "outer" vector. How do you define the size of the "inner" vector?
-
Well i need to define a size only for outer vector, because i use [] operator.
For inner vector i don't have a defined size, and i use append.
Or something like
@
QVector vector;vector.append(element);
@works without a size specified...
For inner vector i let him expand on it's own...
-
Hello.
I've tried to reproduce your problem, but everything went right.
My suggetions are:Analize you code and think of what may go wrong. This might save your time.
Make sure you don't use index that's out of range.
Look at call stack at the moment when you get SIGSEGV.
Look at data structures under debugger since the moment right before creation of your Node object. Look for everything that doesn'n change after object construction or anything that has a strange value.