Hi,
What is the most elegant way of creating a Qt-like multidimentional array since I'm having to mess with:
and access it with:
Obviously the x part of the array doesnt benefit from any of Qt's container properties. Any ideas?
Hi,
What is the most elegant way of creating a Qt-like multidimentional array since I'm having to mess with:
and access it with:
Obviously the x part of the array doesnt benefit from any of Qt's container properties. Any ideas?
QList<QList<double>> ?
double d = myList.at(x).at(y);
Yep, Ive just got that working. I was having problems with it because I was trying to do this:
When I should have been doing:Qt Code:
for( int x = 0; x < 181; x++ ){ theList.append(x); for( int y = 0; y < 2001; y++ ) theList.at(x).append(y); }To copy to clipboard, switch view to plain text mode
Qt 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); }To copy to clipboard, switch view to plain text mode
Cheers,
Phil
I just came up with a crazy idea to represent a 2D array using a tree or a map:
Qt Code:
struct 2DArrayIndex { int x, y; ... }; class 2DArray : public QHash<2DArrayIndex, int> { //... };To copy to clipboard, switch view to plain text mode
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...
Bookmarks