[Qt-interest] QVector with a custom type
OS Prog
osprog at gmail.com
Wed Jul 22 11:14:02 CEST 2009
... that's a simple source that demonstrate the problem...
On Wed, Jul 22, 2009 at 9:56 AM, Thomas Dähling
<t.daehling at googlemail.com>wrote:
> Oh my bad, I totally overlooked that line, clearly I should get a
> coffee before checking e-mails :-)
> Of course resize() should work (otherwise your first assignment would
> have crashed already).
>
> Can you post a minimum compilable example that demonstrates the problem?
>
> 2009/7/22 OS Prog <osprog at gmail.com>:
> > 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/92f9859c/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qvector.zip
Type: application/zip
Size: 1120 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090722/92f9859c/attachment.zip
More information about the Qt-interest-old
mailing list