3
votes

I have to create a QHash with a map QMap inside it, I have tried to write it as follows:

Declaration:

QMap<int,int>price_vol;
QHash<int,QMap<int,int>>table_maintain;
QList<int>data_list;

Definition:

price_vol.insertMulti(stOrderData->Price,stOrderData->Quantity);
table_maintain.insertMulti(stOrderData->TokenNo,price_vol);
data_list = table_maintain.values();

So I want to know: will I get a QMap for a token number which will map to various values with 'price' as key?

1
@guneykayim: How can i print all values of tablemaintain? one nore question,will the values inside price_vol be sorted by itself? - CowboY
What do you mean by printing all values of table_maintain? Values of tablemaintain are QMap type objects, you can't directly print them, you need the print values of values of table_maintain, or we can say values of items of table_maintain. As far as I know values in price_vol will be sorted by Price, but since you're using QHash for table_maintain price_vol items won't be sorted in table_maintain by their tokenNo, they will be random. - guneykayim

1 Answers

0
votes

So I want to know: will I get a QMap for a token number which will map to various values with 'price' as key?

Yes, sure.

How can i print all values of tablemaintain?

Just loop through the containers and print their keys and values as you wish; something like this:

foreach (int key, myContainer.keys())
     qDebug() << key << "," << myContainer.value(key);

will the values inside price_vol be sorted by itself?

Sure, that is the main difference between QMap and QHash. QMap will be ordered based on the key.