[Qt-interest] Using a QList<float> as a float[] parameter
Sean Harmer
sean.harmer at maps-technology.com
Wed Jun 23 15:13:21 CEST 2010
On Wednesday 23 June 2010 14:05:01 Duane Hebert wrote:
> >"Ori Lahav" <vbcrlf at gmail.com> wrote in message
> >>news:AANLkTilQ95HAdXUtmod7T6icybkK6XJAW9TY9xrJanmv at mail.gmail.com... Hi
> >Srdjan,
> >This function is in an external library, can't change it.
>
> You can change your list of floats to std::vector<float> and then pass it
> by ref as
>
> std::vector<float> Floats;
> //fill it
>
> pass it as &Floats[0]
>
> std::vector is guaranteed to be contiguous so this should be safe.
You can also do the same trick with QList<float> I think as that is also
stored in a contiguous section of memory for types where sizeof(type) <=
sizeof(void*).
I still prefer to use
For larger types, QList stores pointers to the objects instead.
Sean
More information about the Qt-interest-old
mailing list