[Qt-interest] copy constructor in template class with QHash pointer member

Andre Somers andre at familiesomers.nl
Tue Aug 25 16:01:07 CEST 2009


Hi,

I have a template class that has a QHash pointer as a member. It uses 
the QHash to store most of it's data (it is a sparse matrix 
implementation). Because I need this class to be a property, it needs to 
be able to be a QVariant and therefore needs to have a copy constructor.

I am trying to write this copy constructor, but I am running into 
crashes. The current (relevant) code is:

template <class T>

SparseMatrix<T>::SparseMatrix(const SparseMatrix<T>& sm) {


m_data = new QHash<quint64, T>;

*m_data = *(sm.m_data);


}


The crash happens at the assignment (last code line). The backtrace 
points further into QHash, but I am willing to assume that QHash itself 
is just fine ;-)


In the case that this is crashing, T is float, but that should not 
matter much I'd think.

Does somebody has a suggestion what I'm overlooking here? I thought I 
could just assign QHash's to each other and use their implicit data 
sharing feature? Thank!

André





More information about the Qt-interest-old mailing list