[Qt-interest] Issue in appending QList Variable

Srdjan Todorovic todorovic.s at googlemail.com
Tue May 5 13:39:38 CEST 2009


Hi,

2009/5/5 Kamakshi Sivaraman <Kamakshi.Sivaraman at lntinfotech.com>:
>
> I am using QList<SomeStructure> as a value inside my QMap. I m unable to
> fill the list with the structure elements. Always the list points to a Bad
> Ptr.
>
> One such example I have tried is:
> struct stlistData{
>                 QString strName;
>                 };
>
>                 stlistData obj;
>                 obj.strName = "XYZ";
>                 QList<stlistData> liststr;
>                 liststr.append(obj);
>
> The QList variable after appending still shows error. Please let me know if
> I have coded correctly.

Yes that should be coded correctly. I've got very similar code in a Qt4 project.

I was wondering: what's the scope of 'liststr' ?

If you destroy it after you leave that stack frame, but you pass a
reference/pointer to the list to some other component before you
return, then the other component would have an invalid QList
reference/pointer.

Hope that helps,

Srdjan



More information about the Qt-interest-old mailing list