[Qt-interest] QVector with a custom type
OS Prog
osprog at gmail.com
Wed Jul 22 10:50:28 CEST 2009
Hi,
Thanks for the reply!
I tought that
*rdata.data()[0].RegData.resize(1);*
will create this element for me....
If the resize() doesn't create/remove elements what is it for then...?
Regards,
Nikolay
On Wed, Jul 22, 2009 at 9:44 AM, Thomas Dähling
<t.daehling at googlemail.com>wrote:
> Of course it crashes, you are trying to use a value that does not
> exist. Use RegData.push_back() instead of RegData.data()[0], the []
> operator for a vector requires the existance of that element.
> Alternately, use resize as you did.
>
> 2009/7/22 OS Prog <osprog at gmail.com>:
> > Hi,
> > I try to use QVector with a custom type:
> >
> > typedef struct
> > {
> > quint32 RegAddress;
> > QVector<quint32> RegData;
> > }regdata_t;
> >
> > Q_DECLARE_TYPEINFO(regdata_t, Q_PRIMITIVE_TYPE);
> >
> >
> > QVector<regdata_t> rdata; <-- declared in the steck
> >
> > when I resize "RegData" to 1 and assign a value:
> >
> > rdata.resize(1);
> > rdata.data()[0].RegAddress = DEVID;
> > rdata.data()[0].RegData.resize(1);
> > rdata.data()[0].RegData.data()[0] = 1; <---
> >
> > the programm crashes:
> >
> > Unhandled exception at 0x0042e6d1 in testusb.exe: 0xC0000005: Access
> > violation reading location 0x00000004.
> >
> > Regards,
> > Nikolay
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090722/436430f1/attachment.html
More information about the Qt-interest-old
mailing list