[Qt-interest] copy constructor in template class with QHash pointer member
Sean Harmer
sean.harmer at maps-technology.com
Tue Aug 25 16:25:31 CEST 2009
Hi,
On Tuesday 25 Aug 2009 15:01:07 Andre Somers wrote:
> 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);
>
>
> }
Have you checked the obvious things like sm.m_data being a valid pointer? Can
you post a complete example please?
> 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!
I can't see why not at a quick glance.
Cheers,
Sean
More information about the Qt-interest-old
mailing list