[Qt-interest] copy constructor in template class with QHash pointer member
Andre Somers
andre at familiesomers.nl
Tue Aug 25 16:47:23 CEST 2009
Hi,
Thanks for your help. See below...
Sean Harmer wrote:
> 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?
I have. sm.m_data is valid, according to the debugger. It should be, as
it is created in the constructor of the SparseMatrix class.
> Can
> you post a complete example please?
>
What else do you need? The whole class definition and implementation is
a bit tricky to give, as it is a bit too big to paste here. However,
here
(http://code.assembla.com/srtools/git/nodes/record_grouper_refactor/common/src)
you can find the matrix.cpp and matrix.h I am working on.
>
>> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
More information about the Qt-interest-old
mailing list