PDA

View Full Version : Best way to represent struct using Qt containers



rajil.s
25th January 2012, 11:33
Hi,

I want to convert the oneitem struct into one of Qts container classes. Oneitem has three components, so cannot use QPair or QList. I need to have array of oneitems. any ideas?


struct itemdetail {
double a;
double b;
} ;

struct oneitem
{
struct itemdetail originalitem;
QString desc;
QMap<int, QPair<struct itemdetail, int> > growth;

};




Cheers

stampede
25th January 2012, 12:14
I need to have array of oneitems.
So why dont you use QList ?


QList<oneitem> list;

Btw. you can skip the "struct" keyword when declaring the variable:


struct itemdetail {
double a;
double b;
} ;

struct oneitem
{
itemdetail originalitem; // 'struct' not needed here
QString desc;
QMap<int, QPair<itemdetail, int> > growth; // 'struct' not needed
};

wysota
25th January 2012, 19:30
In 99% of the cases any data-based structure can just be mapped to QVariantMap.