normaluser
normaluser

Reputation: 57

Nested QMap - How to insert without instantiating

QMap<QString,int> map;

QMap<int,QMap<QString,int>> table;

QMap<QString,int>::iterator iter = map.begin();
int i = 0;
while (iter != map.end()) 
{
   if (condition) {
      table.insert(i++,iter.key(),iter.value());  // <--- this is obviously wrong
   else
      ++iter;
}

So bascially I need to filter our data in map and insert them as new QMap as a value in the table QMap. How to go around with this?

Upvotes: 0

Views: 892

Answers (1)

Former contributor
Former contributor

Reputation: 2576

Since Qt 5.1, when compiling as c++11, you could use an initializer list:

table.insert( i++, QMap<QString,int> {{iter.key(),iter.value()}} );

But the question title says "without instantiating", and that is not possible. This is just another constructor.

Upvotes: 1

Related Questions