There was a need to use this design:
typedef QHash<int, double> Row; typedef QHash<int, Row> Matrix;
And such a code behaves strangely:
Matrix m; //заполняем контейнер некоторым образом int rowNumber = 1; Matrix::const_iterator it = m.constFind(rowNumber); if (it != m.constEnd()) { Row &row1 = it.value();//все хорошо работает Row &row2 = m[rowNumber];//можно поймать сегфолт }
The Qt documentation says that even if there is no key in the hash key, when the operator [] is called, a pair will be added to the hash (key, value) where value is initialized by the default constructor. Here, the key value is guaranteed to be in the hash, but for some reason sometimes a segfolt occurs. Checked on Windows7 32bit, Ubuntu 11.10 64bit; Qt 4.7. What can you say?