[Qt-interest] QVector with a custom type
Thomas Dähling
t.daehling at googlemail.com
Wed Jul 22 10:56:11 CEST 2009
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
>> >
>> >
>
>
More information about the Qt-interest-old
mailing list