Hello!
I'm writing a class using Qt collections classes (i.e. QVector, QMultiHash, QMultiMap). The first class I tried to use was QMultiHash. After getting crash similar to described below, I tried using QMultiMap, got same crash and now tried QVector class.

Back to subject. The class i'm writing looks like this:
Qt Code:
  1. //graph.h
  2. class Graph :public QObject, public QGraphicsItemGroup
  3. {
  4. Q_OBJECT
  5. QVector< QVector <Node*> > nodes;
  6. public:
  7. Graph(QObject* parent=0);
  8. ~Graph();
  9. signals:
  10. void maxLevel(int);
  11. public slots:
  12. Node* addNode(const int level=0);
  13. private slots:
  14. void removeNode(QObject *arg);
  15. private:
  16. void calculateGeometry();
  17. };
To copy to clipboard, switch view to plain text mode 
And the crash happens in this function.
Qt Code:
  1. //graph.cpp
  2. Node* Graph::addNode(const int level)
  3. {
  4. Node* ret=NULL;
  5. if(level<0||level>nodes.count())return ret; //crash here
  6. if(level==nodes.count()) nodes.insert(level,QVector<Node*>());
  7. Node* node=new Node();
  8. ret=node;
  9. node->setText(trUtf8("Level %1").arg(level));
  10. connect(node,SIGNAL(destroyed(QObject*)),this,SLOT(removeNode(QObject*)));
  11. addToGroup(node);
  12. nodes[level].append(node);
  13. calculateGeometry();
  14. emit maxLevel(nodes.count());
  15. return ret;
  16. }
To copy to clipboard, switch view to plain text mode 

A pointer to an object of this class is used inside of a class, derived from QMainWindow.
Being called from it's constructor it works just fine.
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent):
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. //........
  6. Graph* g=new Graph();
  7. g->addNode();
  8. //........
  9. }
To copy to clipboard, switch view to plain text mode 
But when addNode() is called later (not inside constructor, via signal/slot) it crashes on the string I specified. In debug mode it stops on this line inside QVector:
Qt Code:
  1. //qvector.h
  2. //........
  3. inline int count() const { return d->size; }
  4. //........
To copy to clipboard, switch view to plain text mode 

As I said, the same thing happened with QMultiHash and QMultiMap. I'm using Qt 4.8.1 with QtCreator 2.4.1 under Linux Mint 13 (Maya) 64 bit (kernel 3.2.0-23-generic.

Is this an issue of my code or Qt? (I tend to think that this is my code's fault, but I can't find source of the problem. Please help! BTW, The code provided compiles without a single error.