Most elegant Qt Multidimentional array
Hi,
What is the most elegant way of creating a Qt-like multidimentional array since I'm having to mess with:
Code:
QList<double> myList[100]
and access it with:
Obviously the x part of the array doesnt benefit from any of Qt's container properties. Any ideas?
Re: Most elegant Qt Multidimentional array
QList<QList<double>> ?
double d = myList.at(x).at(y);
Re: Most elegant Qt Multidimentional array
Yep, Ive just got that working. I was having problems with it because I was trying to do this:
Code:
for( int x = 0; x < 181; x++ ){
theList.append(x);
for( int y = 0; y < 2001; y++ )
theList.at(x).append(y);
}
When I should have been doing:
Code:
QList<double> temp;
for( int x = 0; x < 181; x++ ){
temp.clear();
for( int y = 0; y < 2001; y++ )
temp.append(y);
theList.append(temp);
}
Cheers,
Phil
Re: Most elegant Qt Multidimentional array
I just came up with a crazy idea to represent a 2D array using a tree or a map:
Code:
struct 2DArrayIndex { int x, y; ... };
class 2DArray : public QHash<2DArrayIndex, int> {
//...
};
One would need a custom method to access the data, so that it returned some default value if the item under specified coordinates would not be present, but apart from that we'd have a nice representation of a sparse 2D array. It wouldn't make sense to do it this way with dense arrays though...