[Qt-interest] QVector with a custom type

Julien Cugnière julien.cugniere at gmail.com
Wed Jul 22 11:02:55 CEST 2009


2009/7/22 OS Prog <osprog at gmail.com>
> 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...?

resize() will create the elements. So your use is valid, even though
using "append" or "push_back" would be better.

I think your problem comes from the "Q_DECLARE_TYPEINFO(regdata_t,
Q_PRIMITIVE_TYPE);" line. It tells Qt that regdata_t has no
constructor/destructor and that none of its member have
constructors/destructor. Which is wrong, because of the QVector
member. So get rid of Q_DECLARE_TYPEINFO, and your code should work.

Generally speaking you never need Q_DECLARE_TYPEINFO. Its only use is
to optimize certain special cases, but using it correctly requires
some very good understanding of the way C++ work.

--
Julien Cugnière




More information about the Qt-interest-old mailing list