I'm converting a Perl program into Qt/C++. Most code has a straightforward conversion into either C++ or Qt function. However, I'm not sure how to migrate the Perl hash of hashes.
Here's an example of the multilevel hashes that I use to organize some data
$series{$uid}{$studynum}{$seriesnum}{'exportseriesid'} = $exportseriesid;
$series{$uid}{$studynum}{$seriesnum}{'seriesid'} = $seriesid;
$series{$uid}{$studynum}{$seriesnum}{'subjectid'} = $subjectid;
$series{$uid}{$studynum}{$seriesnum}{'studyid'} = $studyid;
$series{$uid}{$studynum}{$seriesnum}{'modality'} = $modality;
I've used the QHash to create single level hashes, such as
QHash<QString, QString> cfg;
int n = cfg["threads"].toInt();
Is there a method similar in C++ or using QHash?
UPDATE:
I ended up using nested QMaps. QMap is automatically sorted by key when iterating over it, while QHash is not. Here is the code I ultimately used
/* create a multilevel hash s[uid][study][series]['attribute'] */
QMap<QString, QMap<int, QMap<int, QMap<QString, QString>>>> s;
/* iterate through the UIDs */
for(QMap<QString, QMap<int, QMap<int, QMap<QString, QString>>>>::iterator a = s.begin(); a != s.end(); ++a) {
QString uid = a.key();
/* iterate through the studynums */
for(QMap<int, QMap<int, QMap<QString, QString>>>::iterator b = s[uid].begin(); b != s[uid].end(); ++b) {
int studynum = b.key();
/* iterate through the seriesnums */
for(QMap<int, QMap<QString, QString>>::iterator c = s[uid][studynum].begin(); c != s[uid][studynum].end(); ++c) {
int seriesnum = c.key();
int exportseriesid = s[uid][studynum][seriesnum]["exportseriesid"].toInt();
/* etc... */
}
}
}