struct X { int a, b; QString s; X(int a, int b, QString s): a(a), b(b), s(s) {} }QList<X> ls; ls << X(1,2,"3")<< X(1,2,"3")<< X(1,2,"3"); QList<int> *a; a = (QList<int>*)(&ls); qDebug() << &ls[0] << &ls[1] << &ls[2]; qDebug() << &(*a)[0] << &(*a)[1] << &(*a)[2];
struct A: public Ini {int a;QColor c;QVector<X> xlist;A() {add(INT, &a, "a"); add(CLR, &c, "c"); add(VEC, &xlist, "xlist");} }
C++ (Qt)&vector[i] = &vector[0] + i;
QList<int> *a; a = (QList<int>*)(&ls);
template <typename T>QDataStream& operator<<(QDataStream& out, const std::vector<T>& list){ out << list.size(); foreach (T item, list) out << item; return out;}// И потом запаковываем свой класс:QDataStream& operator<<(QDataStream& out, const A& a) { out << a.x << a.y << a.s1 << a.s2 << a.list; return out; }
struct Ini: public Base{ struct St { QString s; int i; bool b; } st; struct KA: public Base { QColor c; KA() { add(COLR, &c, "c"); } }; QVector<KA> kas; QString configFile; QString lastLogin; Ini() { add(STRNG, &st.s, "st.s"); add(INT, &st.i, "st.i"); add(BOOL, &st.b, "st.b"); add(COLR, &ka.c, "ka.c"); add(VECT, &kas, "kas", sizeof(KA)); add(STRNG, &configFile, "configFile"); add(STRNG, &lastLogin, "lastLogin"); }};
configFile=conflastLogin=last[ka]c=#ff0000[kas=0]c=#ff0000[kas=1]c=#00ff00[st]s=zzzi=120b=true
switch(typeSize){......case 3: ((std::vector<char[3]>)pointer)->resize(itemCount); break;......}
add(STRNG, &st.s, "st.s"); add(INT, &st.i, "st.i");
C++ (Qt)struct CExample { size_t GetPolyNumVer( size_t polyIndex ) const { int index1 = mEntry[polyIndex]; int index2 = (polyIndex < mEntry.size() - 1) ? mEntry[polyIndex + 1] : mEntry.size(); return index2 - index1; } int * GetPolyIndices( size_t polyIndex ) { return &mIndices[mEntry[polyIndex]]; } std::vector <int> mEntry; std::vector <int> mIndices;};